I'm building a GWT application with Maven for dependency resolution and I've got a strange problem with Eclipse when trying to run JUnit tests. I have a standard maven-like structure of sources and tests:
/src/main/java
/src/test/java
If I set the the Java Build Bath > Default output folder of all source folders to:
/MyProject/target/classes
then there are no problems. However, the GWT plugin needs the sources to reside in:
/MyProject/src/main/webapp/WEB-INF/classes
in order to be able to deploy from this directory in development mode, otherwise it complains. However, if I set the output directory of all source folders to this directory, the tests are failing with ClassNotFoundException.
This can be worked-around if I manually add the directory /MyProject/src/main/webapp/WEB-INF/classes
to the JUnit launcher's classpath, so, obviously, the compiled .class files are missing and hence the exception I get. But why doesn't eclipse add the directory to the classpath automatically if I define it to be the default output directory?
I suspect the m2eclipse plugin to be overriding the Default output folder setting, can it be? Because if I set the output folder for /src/main/java
to /target/classes
and src/test/java
to /target/test-classes
, everything works. But if any output directory is set outside of these two, it doesn't work.
I would appreciate any ideas, thank you!
m2eclipse has a storied history of ignoring the project classpath settings when running unit tests. It used to be (0.12 version of m2eclipse and earlier, I think), that if you just gave up fighting and set your project default classpaths to but target/classes (for source code), and target/test-classes (for unit test code), everything would be happy. With 0.13 m2eclipse, this no longer works, as the maven builder appears to put things in target/your-artificat-version-SNAPSHOT/web-inf/classes. Basically, the folder for the artifact that maven builds. This really sucks, since that path includes a version number.
m2eclipse has about exhausted my patience ;-).
A tip: To find out what is going on with your unit test class paths, you can always DEBUG as unit test, then right click on the thread in the debug perspective and pull up "properties". This will show you the complete classpath used for the unit tests, and you can see what the sneaky annoying plugins are doing to your classpath.