score:1

Accepted answer

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.

score:1

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.


Related Query

More Query from same tag