How to create a jar with external libraries included in Eclipse?

后端 未结 8 1458
北恋
北恋 2020-11-22 10:46

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

相关标签:
8条回答
  • 2020-11-22 10:58

    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'.

    0 讨论(0)
  • 2020-11-22 11:01

    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.

    0 讨论(0)
  • 2020-11-22 11:14

    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.

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

    0 讨论(0)
  • 2020-11-22 11:17

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

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

    0 讨论(0)
  • 2020-11-22 11:18

    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").

    0 讨论(0)
  • 2020-11-22 11:20

    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.

    Or

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

    0 讨论(0)
提交回复
热议问题