简体   繁体   中英

Add jar library to eclipse project for exporting

I have a library called Snakeyaml.jar , and I want to add it to my eclipse project, so it will be included in my jar, when I export my project. So far, I only see ways to add an "External Jar" which only adds a jar library to the buildpath, and does NOT include it in the program when being exported! How can I do it, and do I need any plugins for that? Please help!

Thanks.

Adding the jar to your build path is for compilation and runtime, but from eclipse only. A common misconception is that jar files can be added into other jar files, which will never work. What you probably want is extract your library jar into your exported jar. To achieve this:

  1. File - Export
  2. Expand Java node and select Runnable JAR File
  3. In the library handling section, select Extract required libraries into generated JAR

Reference: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fref-export-runnable-jar.htm

While exporting you can chose the File->Export->Runnable Jar Option . Then use the selection like below screen ie Extract required libraries into generated jar

可运行

Okay, so I understand what you are actually asking! You want the Snakeyaml.jar file inside of your exported jar file, and for your program to use its libraries.

To do so, drag and drop the Snakeyaml.jar file into your src folder in eclipse.

Then, go to build path, and instead of looking for external jars for your buildpath, choose to use the jar file that is already in your src folder in eclipse. Once you do that, you should export it and pick to "Extract required libraries into jar file" or something like that, and everything should work well! You will notice upon opening the exported jar file with a tool like Winrar, that the jar you had in your src folder is not there, but the packages of the jar are actually side by side with yours.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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