Exclude JUnit from Eclipse exported JAR

2019-04-24 13:16发布

问题:

I'm using Eclipse JUnit integration which includes the JUnit library automatically into my project. The problem is that when I export my project using the Runnable JAR file destination, it includes JUnit.

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

回答1:

If you're creating your JAR by right clicking on your project and selecting export and then picking JAR File, you can remove your tests from the export by unchecking your test folder. See this related discussion and this example.



回答2:

I've found a solution to the problem by using Ant within Eclipse and the following build.xml:

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


回答3:

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