Create and use a library

Discussion in 'Plugin Development' started by Sharpadogge, Jun 8, 2021.

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

    Sharpadogge

    Hello, I have a question...

    I just want to know briefly how I develop a library for my plugins. I looked at this tutorial for that: https://www.spigotmc.org/wiki/creating-external-libraries/

    I have created a project for myself, as in the tutorial and included practically exactly the same functions. Then I added a new dependency in Maven.

    Code:
            <dependency>
                <groupId>de.sharpadogge</groupId>
                <artifactId>test-library</artifactId>
                <version>1.0.0</version>
                <scope>provided</scope>
            </dependency>
    I can compile my plugin without getting errors and auto-complete works as well (JetBrains IntelliJ is used). However, when I start my test server, I get the following error:

    Code:
    java.lang.NoClassDefFoundError: de/sharpadogge/lib/TestLibrary
        at de.sharpadogge.plugin.Plugin.onEnable(Plugin.java:20) ~[?:?]
    The line of code that causes this error message is this (the same as in the tutorial):

    Code:
    // in onEnable()
    TestLibrary.setPlugin(this);
    Now my question is how I can use this external library. Does the test-library.jar need to be in a specific folder? Or do I have to change something in my IntelliJ settings? Or in my pom.xml? I have absolutely no idea.

    Thanks for reading through my problem description, and thanks in advance for the help.
     
  2. Offline

    Shqep

    In a nutshell, if you want to use an external library, it's either have to be shaded in (with Maven's shade plugin or Gradle's shadow) or it has to be a separate plugin.
    What you can do is make the library as usual, but add a plugin.yml and a main class for Bukkit to load, or shade the entire library in your projects that use it.
     
    davidclue likes this.
Thread Status:
Not open for further replies.

Share This Page