1.15.2 Help on using external libraries in a plugin

Discussion in 'Spigot Plugin Development' started by LightDevelopment, Jan 17, 2020.

  1. First off, I never use these forums or really do too much on this site except download the latest spigot server version every now and again, so I do apologize if this is not the correct place or manner in which to ask for help. (Im new to the forums)

    I was looking at some ways to load some other jar files into my 1.15.1 spigot plugin, and couldn't really get anything to work, that's fine, I found a post on here that I believe would solve my issues. I'm not looking for an alternative method like class loaders or something, I just would like to know if this is even possible

    I don't use maven much, so I started with just a simple library jar, and added it to a normal executable jar, and it worked fine, so I tried to use it in the plugin but it doesn't seem to want to work.
    I get a "java.lang.NoClassDefFoundError: libpack/cclass
    at testies.boot.onEnable(boot.java:9) ~[?:?]"
    I know my library works fine, but I don't know if I'm being dumb and or the information on that post was incorrect.
    I tried to make the plugin with maven and got exactly the same error back. The plugin loads and shows as running in the server, but its just that part of loading the other library class where it screws up.

    So my question is, is this even possible or what am I doing wrong here ?
  2. The thing is if you add a library to your java project you’ll be able to use it in your code but once you export your jar the compiler only export YOUR code, not the library. They assume that you will have your library where you will be using your jar. There’s two way to achieve what you wanna achieve:
    1. Get the source code of the library and add it to your project so it’s gonna be in jar
    2. Use maven to get the library, and maven shade to export the library into your jar
  3. Maven is a powerful tool to learn, I’d definitely suggest using it then shading in your dependencies.
    • Like Like x 1