views:

277

answers:

4

Summary

A brief description of why anyone would want to attempt this. In a Maven project, I have a need to run tests against classes in target/classes, and a need to debug (using the Eclipse Servers plugin) tomcat within the Eclipse IDE, which is loading classes and a number of other assembled resources in target/<name-version-package>/WEB-INF/classes. When my main source folder has output set at the WEB-INF/classes directory, tomcat debugging works great in the IDE. When the ouptut is changed to target/classes, the tests work fine too, as the test resources are properly assembled and loaded outside the context of the package.

Problem

The issue is that I have to manually change my main source directory's output based on the task at hand (testing or debugging in tomcat). The configuration and build changes would be prohibitively complex based on other configuration files, etc. to merely work around this.

Therefore, is there a straightforward way to tell Eclipse to output source into two directories? That way the incremental Maven build of Java class files will be copied into both places and I won't have such a fragile configuration.

+1  A: 

A simpler way may be to build the classes in one directory and have a custom Maven goal (possibly using the antrun plugin) copy them over to the other directory.

Here is a concrete example on copying resources with Maven (and Antrun)

Péter Török
I'm already doing this during normal builds, but no Maven goals appear to execute when I start tomcat from within Eclipse using the plain-old Servers view.
Justin Searls
A: 

Maybe try to configure Maven and Eclipse to use separate output folders.

Pascal Thivent
A: 

I don't think that it is possible to make Eclipse to compile the sources to multiple locations.

In similar situations I have created another project inside the workspace into which I link sources from different places. So, I would have the main project which is used for deployment. Then I would have another project which is used for something else, in this case testing. In your case the other project would link the sources from the main project.

The only problem I have had with this is that I haven't found out how to link sources using relative paths.

To link source folders you have to use Project properties -> Java build path -> Source -> Link Source.

Most probably you will need some resources from the main project too. You can create just the same directory structure inside the other project by creating link folders. When creating a folder into your project you can select from the advanced options "Link to folder in the file system".

Lauri