Loading a Lib with my Plugin

Discussion in 'Spigot Plugin Development' started by Kozs, Jan 30, 2018.

  1. I am loading gson for file saving for my plugin but I am not sure how to make it so I don't get errors for class not found, I assume I have to load it on the server or through the plugin somehow?

    public static final Gson gson = new GsonBuilder().setPrettyPrinting().create();

  2. GSON is a library that's automatically shaded into the Spigot JAR... not sure why it's giving you a class not found exception, post the stack-trace.
    I haven't messed around with GSON though, I'm just here to investigate why you got the error.
    • Agree Agree x 1
  3. There's a possibility that you're using a version which is different from the one Spigot is bundled with. The last time I checked it was bundled with 2.8.0, if you're using anything different from it you have to manually include the library in your plugin. Assuming that you are using maven, you could use the maven shade plugin to shade the library into your jar. Keep in mind you need to set the scope of the dependency as "compile".

    Sample pom.xml taken from Spigot which uses maven shade:
    Code (Text):

        <version>{Your version here}</version>

            <!-- Your other plugins here -->
                    <!-- when downloading via Maven we can pull depends individually -->