Maven External Dependency not found by Spigot (ClassNotFoundException)

Discussion in 'Spigot Plugin Development' started by _robert, Oct 12, 2019.

  1. Hi all, I am new to maven. I need this external api during compile time and runtime (where it will not be provided like spigot would be).

    According to this: http://maven.40175.n5.nabble.com/Compile-and-runtime-dependency-on-the-same-jar-file-td86487.html The scope: compile tag should allow use during runtime, but I still get a java.lang.NoClassDefFoundError when trying to run. My relevant pom.xml:

    Code (Text):
           
    <dependency>
                <groupId>com.github.bhlangonijr</groupId>
                <artifactId>chesslib</artifactId>
                <version>1.1.12</version>
                <scope>compile</scope>
    </dependency>
     
    Thanks for any help.
     
  2. You have to shade the dependency into your JAR.
     
  3. Thank you. Do you have an example I can see, I tried adding this:

    Code (Text):
        <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <configuration>
                    <artifactSet>
                        <includes>
                            <include>com.github.bhlangonij:chesslib</include>
                        </includes>
                    </artifactSet>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        </build>
    But it did not work.
     
  4. Your POM looks correct. Did you see anything wrong in the build log?
     
  5. Spelling mistake, thanks for the help!
     
  6. fyi, the compile scope is default, so there’s no need to explicitly define it for a dependency.