Hi!

I've read about the class path order changes in Maven 2.0.8 compared to earlier 
releases and this is causing some issues in my builds so I wonder if there is a 
best approach to this topic.

I've a class needing a resource file loaded from the class path. This file must 
be a different one in the test scenario compared to the one when performing a 
build.
To simplify, I've set up a small (web-)project simply holding a unitTest, 
loading a resource from the classpath like this:

public void testResourceLoading(){
  URL resURL = 
TestClassLoading.class.getClassLoader().getResource("resource.txt");
  assertNotNull(resURL);
  System.out.println("ResURL: "+resURL);
  assertTrue("Haven't found the resource within test-classes!", 
resURL.toString().endsWith("/target/test-classes/resource.txt"));
}

When performing a "mvn test" with maven 2.0.7 the test passes, hence the 
correct version of the file is loaded.
A test with maven 2.0.8 fails because the file in "/target/classes/" is loaded.

I've read about the forkMode of the surefire plugin, so I tried to set this to 
"never", but then a test with maven 2.0.8 passes and the one with maven 2.0.7 
fails!

Could anyone elaborate on how to deal with this situation?

Thanks in advance and best regards,

    Kurt


Just for the sake of completeness, here's my pom.xml for this very simple 
project:

<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <groupId>at.telbiomed.arc</groupId>
  <artifactId>classLoaderTest</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>classLoaderTest Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>classLoaderTest</finalName>
    <resources>
     <resource>
       <directory>src/main/resources/package/</directory>
       <filtering>false</filtering>
       <includes>
         <include>resource.txt</include>
       </includes>
       <targetPath>/</targetPath>
     </resource>
    </resources>
    <testResources>
       <testResource>
         <directory>src/main/resources/test</directory>
         <filtering>false</filtering>
         <includes>
           <include>resource.txt</include>
         </includes>
         <targetPath>/</targetPath>
       </testResource>
    </testResources>
<!-- the test fails with maven 2.0.7 if these settings will be used, otherwise 
with 2.0.8
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <forkMode>never</forkMode>
        </configuration>
      </plugin>
    </plugins>
-->
  </build>
</project>

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

Reply via email to