jar内的java库
我创建了 mytest.jar 文件,其中包含近 30 个库文件和 jar。 是否可以将所有库 jar 放入 mytest.jar 中,以便我只需要分发 1 个 jar? 也许可以使用清单来完成? 谢谢。
I have created mytest.jar file with library that contains near 30 library files also jar.
Is it possible to put all library jars inside mytest.jar so that I need to distribute only 1 jar?
May be it can be done using manifest?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用标准 Java 类加载器无法从 jars-inside-jars 加载类。但是,可以使用自定义类加载器,例如 UberJar 就是这样工作的。
Maven Shade 插件 采用了不同的方法。它将解压您所依赖的所有罐子,并将它们(以及您自己的类)打包到一个大罐子中。然后就可以使用普通的类加载器了。这更简单,并且无需使用 jarjar 也可以实现。
Loading classes from jars-inside-jars is not possible with the standard Java classloader. However it is possible using a custom classloader, this is how for example UberJar works.
The maven shade plugin takes a different approach. It will unpack all the jars you depend on, and pack them (along with your own classes) into one big jar. Then the normal classloader can be used. This is simpler, and is also possible without maven using jarjar.
不是开箱即用的。然而,One-Jar 提供了一个解决方案。它适用于独立应用程序,我认为这就是您正在制作的。
如果您要制作一个小程序,One-Jar 将无法工作。
Not out of the box. However, One-Jar provides a solution. It works fine for standalone apps, which is what I assume you' re making.
If you're making an applet instead, One-Jar won't work.
通常,人们会使用像
jarjar
这样的 jar 重新打包工具来实现此目的。Usually one uses a jar repacking tool like
jarjar
for this purpose.