Exclude JUnit from Eclipse Exported by JAR

I use the Eclipse JUnit integration, which automatically includes the JUnit library in my project. The problem is that when exporting my project using the destination Runnable JAR file, it includes JUnit.

Is there a way to exclude JUnit (and, ideally, tests) from the exported JAR?

+8
java eclipse jar junit
source share
3 answers

I found a solution to the problem using Ant inside Eclipse and the following build.xml file:

<project> <target name="jar"> <jar destfile="out.jar" basedir="bin"> <zipgroupfileset dir="lib" includes="*.jar" /> <manifest> <attribute name="Main-Class" value="com.example.Main" /> </manifest> </jar> </target> </project> 
+1
source share

If you create a JAR by right-clicking on your project and selecting export, and then selecting a JAR file, you can remove your tests from the export by unchecking the box in the test folder. See this related discussion and this example.

+1
source share

You can remove the JUnit package from the .classpath file. Then export the jar file again.

0
source share

All Articles