Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude test class directory for archiving in Ant

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.

like image 564
bdhar Avatar asked Jun 28 '11 14:06

bdhar


2 Answers

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).

like image 175
Aaron Digulla Avatar answered Nov 15 '22 04:11

Aaron Digulla


<jar destfile="app.jar" basedir="bin" excludes="com/myproject/test/" />
like image 26
Brett Kail Avatar answered Nov 15 '22 05:11

Brett Kail