Solved Load external JAR causes NoClassDefFound

Discussion in 'Plugin Development' started by vemacs, Nov 17, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    vemacs

    I want to use http://code.google.com/p/bitlyj/ within my plugin, and I have added that as a referenced library.
    However, when I run the plugin, I get a NoClassDefFoundError. Obviously, this is caused by the JAR not being found at runtime, so how would I load the entire JAR?

    Thanks in advance.

    I put the jar bitlyj-2.0.0.jar in the main project folder, and I have this in my onEnable:
    Code:
    ((PluginClassLoader) this.getClassLoader()).addURL(new File("bitlyj-2.0.0.jar").toURI().toURL());
    
    However, I still get the same error, even after restarting the server.
     
  2. Offline

    mastersparkle

    Are you using Eclipse?

    [edit] Most Likely you are.

    It would be easier for you to add the External Jar in to the plugin instead of trying to download the jar and then add it while the plugin is loading
     
  3. Offline

    vemacs

    Yes. Here is my resources pane:
    [​IMG]
    The bitlyj is also in my referenced libraries.
     
  4. Offline

    cman1885

    Instead of referencing it like you would with bukkit or another plugin, you need to include it in your jar.
     
  5. Offline

    vemacs

    It is included in my JAR (my JAR is about 6x as big as without including it), as you can see in the resources pane. I have also checked it in the export options.
    My issue is loading the JAR. You can read the steps I took in the original post.

    I am not downloading the JAR. The external JAR is in the plugin. I followed the last post in:
    http://forums.bukkit.org/threads/tutorial-use-external-library-s-with-your-plugin.103781/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  6. Offline

    Comphenix

    I find it's much better to use Maven shading or Ant instead. That's what I use to bundle CGlib in ProtocolLib.

    But of course, you could always just import the source code into your project directly.
     
  7. Offline

    fireblast709

    Include it as a external jar, and place the jar (in your case bitlyj-2.0.0.jar) in the same folder as Craftbukkit.jar. Exactly the same as you would use Craftbukkit or Bukkit as a library
     
  8. Offline

    mastersparkle

    you didnt reference it correctly you need to add it just like you did the CraftBukkit.jar

    (windows)
    right click the project and go to the preferences
    then click java Build path


    add the external jar and it will show up under the referenced libraries tab
     
  9. Offline

    vemacs

    Guys, I achieved my goal another way, but I still want to learn how to do this.
    MasterSparkle: did you read? I already referenced it.
     
  10. Offline

    odin8472

    I remember having this problem earlier and i eventually got it to work. It's been a while and I didn't end up needing the library I imported. Here are the steps I took to get it working as far as I can remember.

    First create a libs folder to hold the external library. I guess right click on the project in the package explorer and go to new folder. Then you need to put your external jar file in the folder that was just created. Right click your project again and go to java build path and click add external jar.
    Next, you need to create a custom manifest file. This is that file that shows up in your META-INF folder, MANIFEST.MF. You need to create your own MANIFEST.MF file with the path to your external jar. Here is mine as an example:
    Manifest-Version: 1.0
    Class-Path: /home/chris/MineDev/PluginA/libs/commons-math3-3.0.jar

    As you can see, the library I was adding was the commons-math from apache, but the bukkit 3d math functions ended up being better in the end.
    Go ahead and put the manifest file into the libs folder created earlier or wherever you choose to keep your resources.

    The last thing you need to do is go to the last screen of the Jar export wizard. click on Use exsiting manifest from workspace and point it to your manifest file. Click finish and you should be good to go.
     
    FameForAim likes this.
  11. Offline

    evilmidget38

  12. Offline

    vemacs

    I said up there that I referred to that thread.

    That was helpful. Thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page