Question

I have a basic web application (dynamic web project in eclipse) with an associated EAR project. I am trying to make sure that my junit test code stays out of the deployment EAR file.

In my web project I have a source folder called "src" and one called "test". I need to keep the .class files from the "test" source folder OUT of the EAR when I export it using eclipse.

I know this is trivial using ant but seems impossible using eclipse.. right click project and export the ear file.. the test classes are always included.

If I manually edit the .setting/org.eclipse.wst.common.component.xml file to remove the tag associated with the test folder it works but if some other developers change anything related to the build path, it gets regenerated...

Am I missing something obvious.. I've googled like crazy to no avail.. checked eclipse's docs and am at a loss..

Was it helpful?

Solution

It doesn't seem to be directly possible, which is bizarre. Here's a couple of workarounds you could try.

Note I'd move the java files from the web project to a Java project (this is probably a good practice to follow anyway). Either way create another "test" Java project and move the test sources to that project. Your test project declares the "main" Java project as a dependency so it has access to the types for testing, but isn't included in the war, so the test classes won't be deployed.

Alternatively if you want to keep the sources in one project, you can configure the test project to use linked resources. I've posted another answer that shows how you can use linked resources to share source locations across projects. With this approach the test sources still aren't on the build path for the main project, so won't be bundled in the jar, but are physically located in the project so source control is simpler.

OTHER TIPS

I'm doing something similar, except with PDE, Using Eclipse 3.7. I am deploying Eclipse/OSGi plugins/bundles, and have two java source directories: src and test

I've tweaked the contents of two eclipse project files to separate test code from the build.

.classpath:

<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry export="false" kind="src" path="test"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry export="false" kind="lib" path="/thirdparty/junit/junit.jar"/>
    <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

These changes were motivated by reading this

I don't know if this will apply to your situation, but I also had to modify a build.properties file, to exclude the results of compiling 'test' from the produced jar file.

source.optimizing.jar = src/
#This doesn't contain test/ because we don't want it in the build.

bin.includes = META-INF/,\
               optimizing.jar
#The junit.jar is also exluded               

When I build the entire project, the test files are completely absent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top