简体   繁体   English

包含库的Java导出jar

[英]Java export jar including libraries

I have been looking around for some time now, but didn't a find way how to export a JAR (not runnable jar ) that contains in it's build path the referenced libraries. 我已经寻找了一段时间,但是没有找到如何导出在其构建路径中包含所引用库的JAR (非runnable jar )的方法。

Using Eclipse , I have included the lib folder which contains the jars of the referenced libraries in the export process. 使用Eclipse ,我在导出过程中包括了lib文件夹,其中包含引用库的jar。
Importing that JAR to another project and calling some method results in a ClassNotFoundException . 将那个JAR导入另一个项目并调用一些方法会导致ClassNotFoundException
Looking at the MANIFEST, I didn't see any reference to those jars in the classpath, though the jars are indeed included in the jar. 看着清单,我没有在类路径中看到对这些jar的任何引用,尽管jar确实包含在jar中。

So my questions are: 所以我的问题是:
1. Is there any way to accomplish the packaging of the non-executable JAR so it will include libraries? 1.有什么方法可以完成对非可执行JAR的打包,因此它将包含库?
2. Is there any best practice for building and deploying a jar that include other jars libraries? 2.是否有构建和部署包含其他jar库的jar的最佳实践?

I tried it too but it doesn't work for me. 我也尝试过,但是对我不起作用。 I added the final .jar file but it doesn't work. 我添加了最终的.jar文件,但是它不起作用。

So, I did a workaround. 因此,我做了一个解决方法。

  1. Extract the .jar file that you want as a dependency. 提取所需的.jar文件作为依赖项。
  2. Copy that content and put it all inside your .jar file. 复制该内容并将其全部放入.jar文件中。
  3. Add your .jar file as dependency inside an eclipse project. .jar文件添加为eclipse项目内的依赖项。
  4. Run it and see if everything is ok. 运行它,看看一切正常。

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

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