I have created a java library project. The binaries are available at <project-dir>/bin
. The test classes are available at <project-dir>/bin/com/myproject/test
. I need to exclude archiving of my test classes. So, I wrote the following code:
<target depends="build-all" name="build-dist">
<jar destfile="app.jar" basedir="bin" excludes="com/myproject/test/*.class" />
</target>
This works fine. But in the archive the directory test
is still available. How to remove this?
Thanks.
The best solution is to keep test Java and class files in different directories. So instead of compiling them into bin
, compile them in a second step into bin-test
. This also makes sure that the non-test code can't see test classes (compilation will fail if you accidentally import a test in a production class).
<jar destfile="app.jar" basedir="bin" excludes="com/myproject/test/" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With