简体   繁体   中英

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.

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/" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM