0

I was making a Minecraft plugin (with maven) and was going to use caffeine for a cache, but when I ran my server with the plugin jar, I got the error:

java.lang.NoClassDefFoundError: com/github/benmanes/caffeine/cache/Caffeine

I am updated to the latest version of caffeine (v3.0.3) and maven (v3.8.1). I honestly have nothing else to show other than that error. I only imported the following caffeine packages:

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine

pom.xml (no repo)

<dependency>
 <groupId>com.github.ben-manes.caffeine</groupId>
 <artifactId>caffeine</artifactId>
 <version>3.0.3</version>
</dependency>

server log: https://pastebin.com/zMzx37dk

Pro Poop
  • 357
  • 5
  • 14
  • The caffeine jar file needs to be distributed to your server along with your plugin, or it needs to be packaged within your jar. – sorifiend Jul 28 '21 at 23:49

1 Answers1

0

It seems that the cause is that the library is not included in the jar file. Try building by adding code like the following to plugins in pom.xml.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.4</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
            </configuration>
        </execution>
    </executions>
</plugin>
Peyang
  • 77
  • 8