简体   繁体   English

创建一个包含外部jar库的Jar文件

[英]Creating a Jar File which includes external jar libraries

I have written a java code using Jcreator that imports Jsoup libraries to execute. 我已经使用Jcreator编写了Java代码,该代码导入了Jsoup库来执行。 These libraries in .jar format. 这些库为.jar格式。 To do so, I went to Project Settings > Required libraries > Add > added the necessary libraries. 为此,我去了项目设置>所需的库>添加>添加了必要的库。 Now, I created a jar file to include this class file and also the jar libraries. 现在,我创建了一个jar文件,以包含该类文件以及jar库。 However, It wont run and gives an error that the Jsoup package is not found. 但是,它将无法运行,并给出一个错误,即找不到Jsoup软件包。 Please help me with this issue. 请帮我解决这个问题。 I have to include the jsoup libraries in to the jar file. 我必须将jsoup库包含在jar文件中。

I have to include the jsoup libraries in to the jar file. 我必须将jsoup库包含在jar文件中。

Hardly. 几乎不。 Not only is your statement incorrect, but it could be illegal if it goes against the distribution rights of the libraries that you're using. 您的陈述不仅不正确,而且如果违反您正在使​​用的库的发行权,也可能是非法的。

Just include the Jsoup jar files with your jar files not inside your jar files when distributing your application. 分发应用程序时,只需将Jsoup jar文件包含在jar文件中,而不将其包含在jar文件中。 Make sure that your jar file manifest file's class-path line refers to the proper location of the jsoup jar files relative to your jar files. 确保jar文件清单文件的class-path行引用了jsoup jar文件相对于jar文件的正确位置。

You should properbly be using an build tool like Maven to define your dependencies (the jars you need) and to build your software. 您应该正确地使用Maven之类的构建工具来定义依赖项(所需的jar)并构建软件。 See here for how to set up your project using maven: http://maven.apache.org/guides/getting-started/index.html 有关如何使用Maven设置项目的信息,请参见此处: http : //maven.apache.org/guides/getting-started/index.html

You cann then use the maven assembly-plugin to build a fat jar containing all needed jars (this might be ill advised as Hovercraft pointed out) or download all required jars for distribution with your project. 然后,您可以使用maven 程序集插件来构建一个包含所有需要的jar的胖子jar(Hovercraft指出可能不建议这样做),或者下载所有必需的jar以便与您的项目一起分发。 See http://maven.apache.org/plugins/maven-assembly-plugin/ for details. 有关详细信息,请参见http://maven.apache.org/plugins/maven-assembly-plugin/

I do not know if jcreator supports maven. 我不知道jcreator是否支持maven。 If not you should consider moving to a more popular IDE like eclipse or netBeans if possible. 如果没有,您应该考虑迁移到更流​​行的IDE(如eclipse或netBeans)。 Both support maven out of the box (and are free). 两者都支持Maven开箱即用(免费)。

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

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