Leszek,

Are you using classifier=tests to define project2->project1 dependency as explained in [1]? Does your test produce expected result on command line?

Please submit a bugreport in JIRA [2] if you believe there is a problem in m2e. We will need sample project and steps to reproduce the problem, see [3] for more general guidelines.


[1] http://maven.apache.org/guides/mini/guide-attached-tests.html
[2] http://jira.codehaus.org/browse/MNGECLIPSE
[3] http://docs.codehaus.org/display/M2ECLIPSE/Reporting+Issues


Leszek Gawron wrote:
Hello,
some contract has changed lately in the way the resources are visible on
the classpath in the project and in other projects.

My case is:

project1:
/src/main/resources/META-INF/test/res.xml
/src/test/resources/META-INF/test/test.xml

now let's see when these resources are visible:

1. /src/main/java/Main.java:
public class Main {
    public static void main( String[] args ) {
System.out.println( "main: " + Main.class.getClassLoader().getResource( "META-INF/test/res.xml" ) ); System.out.println( "test: " + Main.class.getClassLoader().getResource( "META-INF/test/test.xml" ) );
    }
}

this as expected produces:
main: file:/C:/dev/eclipse-workspace/maventestproject1/target/classes/META-INF/test/res.xml
test: null

the test resource is not visible on main classpath.

2. /src/test/java/MainTest.java
public class MainTest {
    public static void main( String[] args ) {
System.out.println( "main: " + MainTest.class.getClassLoader().getResource( "META-INF/test/res.xml" ) ); System.out.println( "test: " + MainTest.class.getClassLoader().getResource( "META-INF/test/test.xml" ) );
    }
}

this as expected produces:
main: file:/C:/dev/eclipse-workspace/maventestproject1/target/classes/META-INF/test/res.xml test: file:/C:/dev/eclipse-workspace/maventestproject1/target/test-classes/META-INF/test/test.xml

both resources from main and test classpath are properly visible


Let's create a project2 that does not hold any resources but simply
makes a dependency on project1 and run the same classes again.

Everything works for main classpath. If I run MainTest in the context of
 project2 I get:

ava.lang.NoClassDefFoundError: MainTest
Caused by: java.lang.ClassNotFoundException: MainTest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main"

The MainTest.class is not visible from project2. If I create
/src/test/java/Main2Test.java in project2:

public class Main2Test {
    public static void main( String[] args ) {
System.out.println( "main: " + Main2Test.class.getClassLoader().getResource( "META-INF/test/res.xml" ) ); System.out.println( "test: " + Main2Test.class.getClassLoader().getResource( "META-INF/test/test.xml" ) );
    }
}

this produces the unexpected result (in fact expected, but surely
unsatisfactory):
main: file:/C:/dev/eclipse-workspace/maventestproject1/target/classes/META-INF/test/res.xml
test: null

This behaviour has changed lately. It was very convenient to create test
resources for some library projects (like logging configuration, some
test property files) which are not put into main jar file but still
visible for any project that imports the library.

Could this be reverted/made configurable?



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to