如何使用Eclipse中包含的外部库创建jar?

时间:2023-01-13 13:27:06

I am done with the project which connects to database (MySQL). Now I want to export the project as jar. But I don't know how to include its external dependencies? Is there any way of doing it in Eclipse or should I use any scripts for that?.

我完成了连接到数据库(MySQL)的项目。现在我想将项目导出为jar。但我不知道如何包含其外部依赖项?有没有办法在Eclipse中执行此操作,还是应该使用任何脚本?

8 个解决方案

#1


119  

When you export your project as a 'Runnable jar' (Right mouse on project -> Export -> Runnable jar) you have the option to package all dependencies into the generated jar. It also has two other ways (see screenshot) to export your libraries, be aware of the licences when deciding which packaging method you will use.

当您将项目导出为“Runnable jar”(项目上的鼠标右键 - > Export - > Runnable jar)时,您可以选择将所有依赖项打包到生成的jar中。它还有另外两种方法(见屏幕截图)来导出您的库,在决定使用哪种打包方法时要注意许可证。

如何使用Eclipse中包含的外部库创建jar?

The 'launch configuration' dropdown is populated with classes containing a main(String[]) method. The selected class is started when you 'run' the jar.

“启动配置”下拉列表中包含一个包含main(String [])方法的类。当您运行jar时,将启动所选的类。

Exporting as a runnable jar uses the dependencies on your build path (Right mouse on project -> Build Path -> Configure Build Path...). When you export as a 'regular' (non-runnable) jar you can select any file in your project(s). If you have the libraries in your project folder you can include them but external dependencies, for example , cannot be included (for maven projects, search here).

导出为可运行的jar使用构建路径上的依赖项(项目右键 - >构建路径 - >配置构建路径...)。当您作为“常规”(不可运行)jar导出时,您可以选择项目中的任何文件。如果项目文件夹中有库,则可以包含它们,但不能包含外部依赖项(例如maven)(对于maven项目,请在此处搜索)。

#2


8  

You could use the Export->Java->Runnable Jar to create a jar that includes its dependencies

您可以使用Export-> Java-> Runnable Jar来创建包含其依赖项的jar

Alternatively, you could use the fatjar eclipse plugin as well to bundle jars together

或者,您也可以使用fatjar eclipse插件将罐子捆绑在一起

#3


5  

You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.

您可以右键单击项目,单击导出,键入'jar',选择'Runnable JAR File Export'。在那里,您可以选择“将所需的库提取到生成的JAR中”。

#4


3  

Personally,

亲自,

None of the answers above worked for me, I still kept getting NoClassDefFound errors (I am using Maven for dependencies). My solution was to build using "mvn clean install" and use the "[project]-jar-with-dependencies.jar" that that command creates. Similarly in Eclipse you can right click the project -> Run As -> Maven Install and it will place the jars in the target folder.

上面的答案都没有为我工作,我仍然得到NoClassDefFound错误(我使用Maven作为依赖项)。我的解决方案是使用“mvn clean install”构建并使用该命令创建的“[project] -jar-with-dependencies.jar”。类似地,在Eclipse中,您可以右键单击项目 - > Run As - > Maven Install,它会将jar放在目标文件夹中。

#5


2  

If you want to export all JAR-files of a Java web-project, open the latest generated WAR-file with a ZIP-tool (e.g. 7-Zip), navigate to the /WEB-INF/lib/ folder. Here you will find all JAR-files you need for this project (as listed in "Referenced Libraries").

如果要导出Java Web项目的所有JAR文件,请使用ZIP工具(例如7-Zip)打开最新生成的WAR文件,导航到/ WEB-INF / lib /文件夹。在这里,您将找到该项目所需的所有JAR文件(如“参考库”中所列)。

#6


0  

While exporting your source into a jar, make sure you select runnable jar option from the options. Then select if you want to package all the dependency jars or just include them directly in the jar file. It depends on the project that you are working on.

将源导出到jar中时,请确保从选项中选择runnable jar选项。然后选择是否要打包所有依赖项jar或直接将它们包含在jar文件中。这取决于您正在进行的项目。

You then run the jar directly by java -jar example.jar.

然后,您可以通过java -jar example.jar直接运行jar。

#7


0  

To generate jar file in eclipse right click on the project for which you want to generate, Select Export>Java>Runnable Jar File,

要在eclipse中生成jar文件,请右键单击要生成的项目,选择Export> Java> Runnable Jar File,

如何使用Eclipse中包含的外部库创建jar?

如何使用Eclipse中包含的外部库创建jar?

Its create jar which includes all the dependencies from Pom.xml, But please make sure license issue if you are using third-party dependency for your application.

它的创建jar包含来自Pom.xml的所有依赖项,但如果您正在为您的应用程序使用第三方依赖项,请确保许可证问题。

#8


0  

If it is a standalone (Main method) java project then Not any specific path put all the jars inside the project not any specific path then right click on the project - > export - > Runnable jar --> Select the lunch configuration and Library handeling then choose the radio button option "Package required libraries into generated jar" -- > Finish.

如果它是一个独立的(Main方法)java项目,那么没有任何特定路径将所有jar放在项目中而不是任何特定路径然后右键单击项目 - > export - > Runnable jar - >选择午餐配置和Library handeling然后选择单选按钮选项“将所需的库打包到生成的jar中” - >完成。

Or

要么

If you have a web project then put all the jars in web-inf/lib folder and do the same step.

如果您有一个Web项目,则将所有jar放入web-inf / lib文件夹并执行相同的步骤。

#1


119  

When you export your project as a 'Runnable jar' (Right mouse on project -> Export -> Runnable jar) you have the option to package all dependencies into the generated jar. It also has two other ways (see screenshot) to export your libraries, be aware of the licences when deciding which packaging method you will use.

当您将项目导出为“Runnable jar”(项目上的鼠标右键 - > Export - > Runnable jar)时,您可以选择将所有依赖项打包到生成的jar中。它还有另外两种方法(见屏幕截图)来导出您的库,在决定使用哪种打包方法时要注意许可证。

如何使用Eclipse中包含的外部库创建jar?

The 'launch configuration' dropdown is populated with classes containing a main(String[]) method. The selected class is started when you 'run' the jar.

“启动配置”下拉列表中包含一个包含main(String [])方法的类。当您运行jar时,将启动所选的类。

Exporting as a runnable jar uses the dependencies on your build path (Right mouse on project -> Build Path -> Configure Build Path...). When you export as a 'regular' (non-runnable) jar you can select any file in your project(s). If you have the libraries in your project folder you can include them but external dependencies, for example , cannot be included (for maven projects, search here).

导出为可运行的jar使用构建路径上的依赖项(项目右键 - >构建路径 - >配置构建路径...)。当您作为“常规”(不可运行)jar导出时,您可以选择项目中的任何文件。如果项目文件夹中有库,则可以包含它们,但不能包含外部依赖项(例如maven)(对于maven项目,请在此处搜索)。

#2


8  

You could use the Export->Java->Runnable Jar to create a jar that includes its dependencies

您可以使用Export-> Java-> Runnable Jar来创建包含其依赖项的jar

Alternatively, you could use the fatjar eclipse plugin as well to bundle jars together

或者,您也可以使用fatjar eclipse插件将罐子捆绑在一起

#3


5  

You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.

您可以右键单击项目,单击导出,键入'jar',选择'Runnable JAR File Export'。在那里,您可以选择“将所需的库提取到生成的JAR中”。

#4


3  

Personally,

亲自,

None of the answers above worked for me, I still kept getting NoClassDefFound errors (I am using Maven for dependencies). My solution was to build using "mvn clean install" and use the "[project]-jar-with-dependencies.jar" that that command creates. Similarly in Eclipse you can right click the project -> Run As -> Maven Install and it will place the jars in the target folder.

上面的答案都没有为我工作,我仍然得到NoClassDefFound错误(我使用Maven作为依赖项)。我的解决方案是使用“mvn clean install”构建并使用该命令创建的“[project] -jar-with-dependencies.jar”。类似地,在Eclipse中,您可以右键单击项目 - > Run As - > Maven Install,它会将jar放在目标文件夹中。

#5


2  

If you want to export all JAR-files of a Java web-project, open the latest generated WAR-file with a ZIP-tool (e.g. 7-Zip), navigate to the /WEB-INF/lib/ folder. Here you will find all JAR-files you need for this project (as listed in "Referenced Libraries").

如果要导出Java Web项目的所有JAR文件,请使用ZIP工具(例如7-Zip)打开最新生成的WAR文件,导航到/ WEB-INF / lib /文件夹。在这里,您将找到该项目所需的所有JAR文件(如“参考库”中所列)。

#6


0  

While exporting your source into a jar, make sure you select runnable jar option from the options. Then select if you want to package all the dependency jars or just include them directly in the jar file. It depends on the project that you are working on.

将源导出到jar中时,请确保从选项中选择runnable jar选项。然后选择是否要打包所有依赖项jar或直接将它们包含在jar文件中。这取决于您正在进行的项目。

You then run the jar directly by java -jar example.jar.

然后,您可以通过java -jar example.jar直接运行jar。

#7


0  

To generate jar file in eclipse right click on the project for which you want to generate, Select Export>Java>Runnable Jar File,

要在eclipse中生成jar文件,请右键单击要生成的项目,选择Export> Java> Runnable Jar File,

如何使用Eclipse中包含的外部库创建jar?

如何使用Eclipse中包含的外部库创建jar?

Its create jar which includes all the dependencies from Pom.xml, But please make sure license issue if you are using third-party dependency for your application.

它的创建jar包含来自Pom.xml的所有依赖项,但如果您正在为您的应用程序使用第三方依赖项,请确保许可证问题。

#8


0  

If it is a standalone (Main method) java project then Not any specific path put all the jars inside the project not any specific path then right click on the project - > export - > Runnable jar --> Select the lunch configuration and Library handeling then choose the radio button option "Package required libraries into generated jar" -- > Finish.

如果它是一个独立的(Main方法)java项目,那么没有任何特定路径将所有jar放在项目中而不是任何特定路径然后右键单击项目 - > export - > Runnable jar - >选择午餐配置和Library handeling然后选择单选按钮选项“将所需的库打包到生成的jar中” - >完成。

Or

要么

If you have a web project then put all the jars in web-inf/lib folder and do the same step.

如果您有一个Web项目,则将所有jar放入web-inf / lib文件夹并执行相同的步骤。