How to fix: java.lang.ClassNotFoundException: net.wesjd.anvilgui.AnvilGUI$Builder
protoxon opened this issue · comments
I keep on getting the java.lang.ClassNotFoundException: net.wesjd.anvilgui.AnvilGUI$Builder whenever I try to create the gui how do I fix it. It may have to do with shade not being set up correctly but because I'm new to maven I cant tell what would cause it.
4.0.0
<groupId>protoxon.com</groupId>
<artifactId>server</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Server</name>
<description>main server plugin</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version> <!-- The version must be at least 3.3.0 -->
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>net.wesjd.anvilgui</pattern>
<shadedPattern>protoxon.com.server.anvilgui</shadedPattern> <!-- Replace [YOUR_PLUGIN_PACKAGE] with your namespace -->
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludeDefaults>false</excludeDefaults>
<includes>
<include>protoxon.com.server.anvilgui</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
<version>1.7.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
public static void searchMenu(Player player) {
new AnvilGUI.Builder()
.onClose(stateSnapshot -> {
stateSnapshot.getPlayer().sendMessage("You closed the inventory.");
})
.onClick((slot, stateSnapshot) -> { // Either use sync or async variant, not both
if(slot != AnvilGUI.Slot.OUTPUT) {
return Collections.emptyList();
}
if(stateSnapshot.getText().equalsIgnoreCase("you")) {
stateSnapshot.getPlayer().sendMessage("You have magical powers!");
return Arrays.asList(AnvilGUI.ResponseAction.close());
} else {
return Arrays.asList(AnvilGUI.ResponseAction.replaceInputText("Try again"));
}
})
.preventClose() //prevents the inventory from being closed
.text("test") //sets the text the GUI should start with
.title("title") //set the title of the GUI (only works in 1.14+)
.plugin(JavaPlugin.getPlugin(Server.class)) //set the plugin instance
.open(player);
}
Try to replace your dependency declarations with this:
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.wesjd</groupId>
<artifactId>anvilgui</artifactId>
<version>1.7.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
If that does not work, I cannot help you any further.
I am still receiving the same error dose anyone know how to fix this issue?
I figured it out instead of doing build artifacts I had to run the maven build which then created the jar with the AnvilGUI classes in the projects target folder.
For anyone who experiences this issue:
In IntelliJ, on the right hand side, click "Maven", and expand "Lifecycle" Select "Package" and click the green arrow "Run Maven Build". once its done building two jars will be created in your projects target folder one called original-JarName-1.0 and JarName-1.0 you want to use the one called JarName-1.0 as it will contain the AnvilGUI classes.
also if you want to change the directory where the shaded jar is created you can add this to your maven plugins:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<outputDirectory>SET DIRECTORY HERE</outputDirectory><!-- changes output directory of the shaded jar -->
</configuration>
</plugin>