简体   繁体   中英

Using JAR inside a jar

I created a JAR file from my java project. Using Eclipse, I added a JAR as a referenced library in my own project. However, now when I try to run my program's JAR using java -jar myProgram.jar , I get an exception stating that my referenced jar is not available.

So how can I create a JAR consisting a reference to a different JAR and make it work?

Right, an executable JAR cannot contain its own JAR dependencies.

You have to have the main class and classpath set in the executable JAR manifest, then package all your JAR dependencies along with the executable JAR in a relative directory structure that matches the manifest CLASSPATH. Reading this might help.

You need to use Eclipse's runnable JAR exporter. Since Eclipse 3.5 you've the following options when you rightclick project, choose Export > Runnable JAR file :

替代文字

Either way, Eclipse should take care that you'll be able to run the JAR the way you want on the exported location.

See jarjar project. It is exactly what you are looking for. http://code.google.com/p/jarjar/

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