how to pack jar file without containing depedency

2019-07-21 17:40发布

问题:

I want to pack jar file without containing depedency jar libraries using eclipse IDE. I used these steps to pack but the result jar file always contains jar libraries. Some steps I did

Jar file I want to pack is jar library not runable jar file

Thanks

回答1:

In eclipse, when you are creating a jar file, select option named 'JAR file' and not 'Runnable JAR'. When you click on next, you will get a list of items which you need to include while creating your jar file with a check box in front of each item. Just don't select the items you don't want to export (in your case dependent libraries).

Hope this helps.



回答2:

Under Export, click Jar file and not Runnable Jar file



回答3:

I would use an ant task...

<zip destfile="${backupJar}" update="true" basedir="${basedir}/../../"
        includes="**/*.xml*, **/*.java"
        compress="true"/>

Remember that a jar is really a zip file with a different extension.

See

http://ant.apache.org/manual/Tasks/zip.html

EDIT: you specifically asked how to ignore dependencies. This is achieved by using the excludes attribute of the zip task, for example:

    <zip destfile="${backupJar}" update="true" basedir="${remotedir}/../"
        excludes="**/lib/testonly.zip, 
              **/lib/ms*.jar, 
          **/*.tmp" 
        includes="exported/**/*.*, exported/jf123/**/*.*" compress="true"/>