maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ondřej Černoš" <cern...@gmail.com>
Subject Re: classpath, tests, resources
Date Mon, 22 Oct 2007 12:25:49 GMT
Hi Adam,

thanks for quick answer. The target/classes directory contains the
production log4j.properties file. I always thought maven uses the
target/test-classes directory as the classpath entry during the tests
- it contains the correct version of the log4j.properties file, but it
seems the target/classes directory is on the test classpath too, and
that it is even the first target directory mentioned on the classpath.

I was probably wrong. I'll try the profile tricks.

ondrej cernos

On 10/22/07, Adam Hardy <adam.maven@cyberspaceroad.com> wrote:
> Hi Ondrej
>
> looks like mvn is not only picking up the production log4j.properties file
> but
> it's also probably not substituting ${catalina.home}
>
> Check in your target/classes directory for log4j.properties and see if it's
> substituted it.
>
> Secondly, log4j uses the first log4j.properties it comes across, so it's not
> going to see the second one in src/test/resources
>
> There are many different ways of doing it - having just one log4j.properties
> in
> src/main/resources and doing substitution using parameters from a default
> profile for testing would be one method. You could change those by invoking
> a
> production profile when you build the war for release.
>
> Ondřej Černoš on 22/10/07 13:04, wrote:
> > I am experiencing a problem with testing and resources. Basically, it
> > seems the production and not the test resources are used when running
> > tests.
> >
> > I have two log4j.properties files, one defines appender as file
> > appender in src/main/resources:
> >
> > log4j.appender.dest1=org.apache.log4j.RollingFileAppender
> > log4j.appender.dest1.File=${catalina.home}/logs/provisioning.log
> >
> > the test one in src/test/resources defines console appender:
> >
> > log4j.appender.dest1=org.apache.log4j.ConsoleAppender
> >
> > When I run mvn clean test, I end up with an exception:
> >
> > java.io.FileNotFoundException: /logs/provisioning.log (No such file or
> > directory)
> >         at java.io.FileOutputStream.openAppend(Native Method)
> >         at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
> >         at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
> >         at org.apache.log4j.FileAppender.setFile(FileAppender.java:289)
> >         at
> org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:167)
> >         at
> org.apache.log4j.FileAppender.activateOptions(FileAppender.java:163)
> >         at
> org.apache.log4j.config.PropertySetter.activate(PropertySetter.java:256)
> >         at
> org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:132)
> >         at
> org.apache.log4j.config.PropertySetter.setProperties(PropertySetter.java:96)
> >         at
> org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:654)
> >         at
> org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:612)
> >         at
> org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:509)
> >         at
> org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:415)
> >         at
> org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:441)
> >         at
> org.apache.log4j.helpers.OptionConverter.selectAndConfigure(OptionConverter.java:470)
> >         at org.apache.log4j.LogManager.<clinit>(LogManager.java:122)
> >         at org.apache.log4j.Logger.getLogger(Logger.java:104)
> >         at
> com.mycompany.project.I18NProviderInvocationHandler.<init>(I18NProviderInvocationHandler.java:80)
> >
> > however, when I delete the production log4j.properties file, the tests
> pass.
> >
> > This is what System.out.println(System.getProperty("java.class.path"));
> returns:
> >
> >
> /home/me/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-1.0-alpha-7.jar
> >
> /home/me/.m2/repository/org/codehaus/plexus/plexus-utils/1.4.5/plexus-utils-1.4.5.jar
> >
> /home/me/.m2/repository/org/apache/maven/surefire/surefire-api/2.4-jboss-1-SNAPSHOT/surefire-api-2.4-jboss-1-SNAPSHOT.jar
> >
> /home/me/.m2/repository/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.jar
> >
> /home/me/.m2/repository/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar
> > /home/me/.m2/repository/commons-lang/commons-lang/2.1/commons-lang-2.1.jar
> >
> /home/me/.m2/repository/org/apache/maven/surefire/surefire-booter/2.4-jboss-1-SNAPSHOT/surefire-booter-2.4-jboss-1-SNAPSHOT.jar
> > /home/me/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
> >
> > However, when run from eclipse (the test fails the same way as when
> > run from command line), the classpath looks different:
> >
> > /home/me/workspace.3.3/provisioning/src/main/resources/
> > /home/me/workspace.3.3/provisioning/src/test/resources/
> > /home/me/workspace.3.3/provisioning/target/classes/
> > /home/me/workspace.3.3/project/target/classes/
> > /home/me/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar
> >
> /home/me/.m2/repository/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar
> > /home/me/.m2/repository/com/mycompany/ipnutil/1.0.1/ipnutil-1.0.1.jar
> > /home/me/.m2/repository/com/swiftmq/jndi/6.1.0/jndi-6.1.0.jar
> > etc.
> >
> > mvn help:effective-pom seems ok:
> >
> > <resources>
> >   <resource>
> >
> <directory>/home/me/workspace.3.3/provisioning/src/main/resources</directory>
> >   </resource>
> > </resources>
> > <testResources>
> >   <testResource>
> >
> <directory>/home/me/workspace.3.3/provisioning/src/test/resources</directory>
> >   </testResource>
> > </testResources>
> >
> > all is run on maven 2.0.7 and java 1.6.0_01.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Mime
View raw message