Using third party libraries when building plugins

Discussion in 'Plugin Development' started by docpify, Mar 22, 2012.

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

    docpify

    Hello,

    I have a plugin where I wish to use external libraries rather than having all the code in a single jar..
    How can I do this?
    Dumping my other jars in ~/bukkit/lib on the server does not seem to do anything.
    If I put it in ~/bukkit/plugins I get complaints about plugin.yml (obviously)

    I jeg get a java.lang.NoClassDefFoundException for my interfaces..

    Please advise.

    // Cheers, doc p
     
  2. Offline

    Father Of Time

    You can drop the classes into a separate jar file and import that external jar like you do Bukkit.
     
  3. Offline

    docpify

    I do that... how do I get it to run in bukkit?

    Okay, after finding and fixing one silly mistake, here is the problem I am running into:

    23:11:47 [SEVERE] Error occurred while enabling RunsafeMinecraftPluginFramework v1.0 (Is it up to date?)
    java.lang.NoClassDefFoundError: org/picocontainer/DefaultPicoContainer
    at me.Kruithne.RMPF.RMPF.onEnable(RMPF.java:17)
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:336)
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:363)
    at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:250)
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:232)
    at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:184)
    at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:53)
    at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:490)

    the file picocontainer-2.14.1.jar has been put in lib/

    If I move pico to plugins, I get, expectedly:
    23:13:58 [SEVERE] Could not load 'plugins/picocontainer-2.14.1.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml

    So, I ask again.. how do I use third party libraries with bukkit?

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

    Don Redhorse

    hmm perhaps xZise @hidrenda know
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    Your choices are either to shade the jar into your plugins jar, or modify the class path the server starts with. possibly try putting your library jar in the same directory as craftbukkit.jar
     
  6. Offline

    docpify

    I've tried modifying classpath when I run bukkit, but all I've achieved is making it not see the config so far - it tries to listen on the default port on startup.

    I was looking at how to merge jars together..
    It seems there are some tools like "jar jar links" and something else, related to maven, but I found the web page of those to be completely opaque..
    Preferably, I would prefer a solution that worked nicely with Eclipse..

    I am also experiencing issues with inter-plugin dependency problems..

    Plugin A contains no features and is actually a class library
    Plugin B extends plugin A, but fails to find interface definitions from plugin A.

    If I end up having to merge everything into a single jar, then I think the gains have been entirely lost :(

    // doc
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    if you are using maven, loot at the maven shade plugin
     
  8. Offline

    Don Redhorse

    I know that several people are using libraries... ask the LWC developer, he should know..
     
  9. Couple options.
    • Shade into the Jar (Maven plugin)
    • Manually include the class files
    • Download the jar and run it at runtime
    • Modify the class path the server starts with
     
  10. Offline

    Technius

    You could also try to find a solution that doesn't use libraries.
     
  11. Offline

    comp8nerd4u2

    I'm amazed you haven't gotten a proper answer yet -.- If you know how to export a project with a modified manifest.mf then add the following line to the end of your manifest:
    Code:
    Class-Path: lib/thirdpartylibrary.jar
    You MUST add a line at the end of your file. I repeat: "add a line at the end of the manifest file." This cannot be stressed enough. Also, I really shouldn't have to say that you have to replace "thirdpartylibrary" with the name of your third party library xD Then place the third party library in "some/server/path/plugins/lib". This works for me and i'm using the Apache Commons IO lib with my plugin. Good luck :)
     
    ZerothAngel, docpify and Don Redhorse like this.
  12. Offline

    docpify

    Thanks, comp8!

    I now have the references working like I wanted :)

    Now I just need to make my code work ;)

    org.picocontainer.injectors.AbstractInjector$NotConcreteRegistrationException: Bad Access: 'me.Kruithne.RMPF.RMPFConfiguration' is not instantiable

    is a hell of a lot better than the other exceptions..
     
  13. Offline

    comp8nerd4u2

    Knowledge is power :D and power FTW! In all seriousness, I had to figure this out on my own, but soon realized that Oracle had documentation on the whole ordeal. When in doubt, look to the Sun. Er, I mean Oracle. Lol
     
  14. Offline

    xZise

    Hmmm, if I added it into the plugin's manifest file and it works for me if the lib directory is where the craftbukkit.jar is and not in the plugins directory.

    Fabian
     
  15. Offline

    comp8nerd4u2

    I believe it varies between JVM implementations. Some might make the class loader look in the working directory and others might make it look relative to the loading jar.

    EDIT: I use the official Sun JDK and JRE for my server.

    EDIT 2: If you want to be REALLY friendly to your plugin downloaders, dynamically load and use your third party library. That way, you are in control of where you load the library from.
     
Thread Status:
Not open for further replies.

Share This Page