简体   繁体   English

在jar里面使用JAR

[英]Using JAR inside a jar

I created a JAR file from my java project. 我从我的java项目中创建了一个JAR文件。 Using Eclipse, I added a JAR as a referenced library in my own project. 使用Eclipse,我在自己的项目中添加了一个JAR作为引用库。 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. 但是,现在当我尝试使用java -jar myProgram.jar运行程序的JAR时,我得到一个异常,说明我引用的jar不可用。

So how can I create a JAR consisting a reference to a different JAR and make it work? 那么如何创建一个包含对不同JAR的引用并使其工作的JAR呢?

Right, an executable JAR cannot contain its own JAR dependencies. 是的,可执行JAR不能包含自己的JAR依赖项。

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. 您必须在可执行JAR清单中设置主类和类路径,然后将所有JAR依赖项与可执行JAR一起打包到与清单CLASSPATH匹配的相对目录结构中。 Reading this might help. 阅读可能有所帮助。

You need to use Eclipse's runnable JAR exporter. 您需要使用Eclipse的可运行JAR导出器。 Since Eclipse 3.5 you've the following options when you rightclick project, choose Export > Runnable JAR file : 从Eclipse 3.5开始,当你右键单击项目时,你有以下选项,选择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. 不管怎样,Eclipse应该注意你能够在导出的位置以你想要的方式运行JAR。

See jarjar project. jarjar项目。 It is exactly what you are looking for. 这正是你要找的。 http://code.google.com/p/jarjar/ http://code.google.com/p/jarjar/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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