Lisa --

You don't need to make any modifications to the mvn script to accomplish
what you're trying to do.  Here's what we do...

1) Set up a directory that will contain resource/configuration files
that you want available when you run your tests.  For us, we use
${basedir}/src/test/config

2) Put any resource/configiguration files you want available during
tests in that directory.  For your situation, you'd put the log4j.xml
file in the ${basedir}/src/test/config directory.

3) Add an entry to the build/testResources element in your pom.xml.
Here's an example:
  <build>
    <testResources>
      <testResource>
        <directory>src/test/config</directory>
        <includes>
          <include>log4j.xml</include>
        </includes>
      </testResource>
    </testResources>
  </build>
You need to add an 'include' entry for each resource.  Check out
http://maven.apache.org/ref/current/maven-model/maven.html#class_testRes
ource for more details on what you can do with the testResources
element.

With these changes in place, Maven will copy to the test/classes folder
all of the test resources you've listed.  The test/classes folder is
included in the class path when Maven runs your tests, so log4j will
utilize the log4j.xml file that was originally located in
src/test/config.

As far as turning on log4j's debugging, just set the  debug attribute in
the root element to "true". 

Ron Gallagher 
Cingular Wireless

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Lisa
Sent: Tuesday, January 23, 2007 5:17 PM
To: [email protected]
Subject: How to use log4j (log4j.xml) and Maven and Junit??

I have written some JUnit tests and put them in the standard layout for
test
cases under Maven.  The tests use log.debug(msg), log.info(msg) etc.

The tests run OK.

So now I created a simple log4j.xml file with an appender and a logger
that
filters only the logging messages in my test case (by package).

When I run maven (mvn test), how do I tell it where my log4j.xml is and
how to
use log4j logging?

I have tried everything.  I edited the "mvn" script under the install
directory
to include the following:

 exec "$JAVACMD" \
   $MAVEN_OPTS \
   -classpath "${M2_HOME}"/core/boot/classworlds-*.jar \
   "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
   "-Dmaven.home=${M2_HOME}"  \
   "-Dmaven.junit.sysproperties=log4j.configuration" \
   "-Dlog4j.configuration=file:C:\tmp\log4j.xml" \
   ${CLASSWORLDS_LAUNCHER} $QUOTED_ARGS


this does not work (have tried with and without file:.

---
I have included a something similiar on the mvn command line:
   mvn -Dlog4j.configuration=c:\tmp\log4j.xml  test

this does not work (have included =file:c:\tmp... as well

---
I have also tried setting properties in the pom.xml like so:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>false</skip>
                    <useFile>false</useFile>

                    <systemProperties>
                        <property>
                            <name>maven.junit.sysproperties</name>
                            <value>log4j.configuration</value>
                        </property>
                        <property>
                            <name>log4j.configuration</name>
                            <value>file=:c:\tmp\log4j.xml</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>

---
and 

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>false</skip>
                    <useFile>false</useFile>

                    <systemProperties>
                        <property>
                            <name>maven.junit.sysproperties</name>
                            <value>log4j.configuration</value>
                        </property>
                        <property>
                            <name>log4j.configuration</name>
                            <value>c:\tmp\log4j.xml</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>

--- and  (log4j.xml is in same directory as pom.xml) this does not work
either.


            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>false</skip>
                    <useFile>false</useFile>

                    <systemProperties>
                        <property>
                            <name>maven.junit.sysproperties</name>
                            <value>log4j.configuration</value>
                        </property>
                        <property>
                            <name>log4j.configuration</name>
                            <value>log4j.xml</value>
                        </property>
                    </systemProperties>
                </configuration>
            </plugin>


---
none of these work.  Any ideas on how to integrate Maven2, Log4J and
Junit would
be greatly appreciated.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to