How to export an Eclipse Project with External Jar dependencies?

33,355

Use the Runnable JAR file export option.

Click on your project - export - java- runnable jar file - select the option to pack requires libraries in the jar

Share:
33,355
funseiki
Author by

funseiki

Python wrestler, by day. High-fiber eating, app-developing, video game playing being, by night.

Updated on July 31, 2022

Comments

  • funseiki
    funseiki almost 2 years

    In Processing, I'd like to import a library I've written in Java which wraps around an external library (a .jar file).

    Processing appears to import my own library, but when I call the constructor (which references some classes in the external library), I get a java.lang.NoClassDefFoundError in the Processing GUI console.

    If instead of including the External .jar in my Eclipse buildpath, I use the library's actual source code and export all of that, Processing does not complain.

    How might I be able to package up this project so that I don't have to include all of the library's source code (and instead just include the .jar file) in my Eclipse project?


    Update: As per N.L.telaviv 's suggestion, I chose to export as a Runnable JAR. What worked for me was to select the option "Copy required libraries into a sub-folder next to the generated JAR." Here, another folder is created next to where your .jar is output containing the referenced .jar libraries.

    Update2: The other option which works is "Extract required libraries into generated JAR." Doing so allows the JAR to access the references internally. It seemed as though the same would have worked with N.L.telaviv 's suggestion, but that does not appear to be the case. Choose this option if you don't want to have any extra files. You'll notice, if you explore the .JAR file, that the external library is in a separate package folder.

  • funseiki
    funseiki over 11 years
    Just tried that, no luck. The only difference here was that along with importing MyProjectPackage.*, Processing also imports org.eclipse.jdt.internal.jarinjarloader.*
  • Nimrod007
    Nimrod007 over 11 years
    check that The class path definition in the MANIFEST has every JAR in it
  • funseiki
    funseiki over 11 years
    Are you referring to the .classpath file? If that's the case, then it does have the .jar. I also found that instead of choosing to package into the generated jar, if I choose "Copy required libraries into a sub-folder next to the generated JAR", it appears to work.
  • Cardinal System
    Cardinal System over 4 years
    My project does not have a main class. It is not meant to be an independent application.