I made a jar file including some code that is useable for me to create minecraft plugins and wanted to make a local repository to the other file, which is called lavidefaultlib-1.3.jar.
The lavidefaultlib is stacked on a different path, both java programs are on D:/.
Everytime I try to start the minecraft server, that has the plugin on it just says it cannot find the class. The Error message of the server looks like this:
java.lang.NoClassDefFoundError: com/lavi/GameMode/SPLi_GameMode
at java.base/java.lang.ClassLoader.defineClass1(Native Method) ~[?:?]
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1027) ~[?:?]
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:206) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:593) ~[?:?]
at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:117) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:112) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?]
at com.Lavi.Init.FileInit.onEnable(FileInit.java:30) ~[?:?]
at com.Lavi.SPLi_Main_Main.onEnable(SPLi_Main_Main.java:31) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:267) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:492) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_21_R1.CraftServer.enablePlugin(CraftServer.java:575) ~[spigot-1.21.1-R0.1-SNAPSHOT.jar:4306-Spigot-a759b62-bd8aded]
at org.bukkit.craftbukkit.v1_21_R1.CraftServer.enablePlugins(CraftServer.java:489) ~[spigot-1.21.1-R0.1-SNAPSHOT.jar:4306-Spigot-a759b62-bd8aded]
at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:641) ~[spigot-1.21.1-R0.1-SNAPSHOT.jar:4306-Spigot-a759b62-bd8aded]
at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:426) ~[spigot-1.21.1-R0.1-SNAPSHOT.jar:4306-Spigot-a759b62-bd8aded]
at net.minecraft.server.dedicated.DedicatedServer.e(DedicatedServer.java:269) ~[spigot-1.21.1-R0.1-SNAPSHOT.jar:4306-Spigot-a759b62-bd8aded]
at net.minecraft.server.MinecraftServer.y(MinecraftServer.java:1017) ~[spigot-1.21.1-R0.1-SNAPSHOT.jar:4306-Spigot-a759b62-bd8aded]
at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:318) ~[spigot-1.21.1-R0.1-SNAPSHOT.jar:4306-Spigot-a759b62-bd8aded]
at java.base/java.lang.Thread.run(Thread.java:1583) [?:?]
Caused by: java.lang.ClassNotFoundException: com.lavi.GameMode.SPLi_GameMode at org.bukkit.plugin.java.PluginClassLoader.loadClass0(PluginClassLoader.java:160) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.java.PluginClassLoader.loadClass(PluginClassLoader.java:112) ~[spigot-api-1.21.1-R0.1-SNAPSHOT.jar:?] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?] ... 21 more
The class com.lavi.GameMode.SPLi_GameMode shold be the class in my lavidefaultlib.
The com.Lavi.SPLi_Main_Main file is the Main file of my minecraft plugin.
Both java projects have a POM file and are compileable.
In the MainMinecraft plugin (not the lavidefaultlib) I used the default spigot resository and my own one that shold refer to the file:
<repository>
<id>lavilib</id>
<url>file://D:/Minecraft/MinecraftPlugins/LaviDefault/lavidefaultlib/target/</url>
</repository>
I also placed a <dependency>
<groupId>..</groupId>
<artifactId>Lavidefaultlib</artifactId>
<version>1.3</version>
<scope>provided</scope>
I do neighter know wether the dependency nor the repository makes sense. I looked for many things on the internet, but most of them desribed different solutions and none of them worked on my problem. Also the answers I found were eighter not for minecraft plugins or not with maven, it seems like it works diffrent here.
How the code of the main minecraft plugin looks (Simplified, only important parts for the problem are included):
package com.Lavi.Init;
import com.lavi.SPLi_Main_Main;
public class FileInit { //This Class is my init class, it should initialiye the lavidefaultlib using a static method
public static void onEnable(JavaPlugin ThePlugin) { //This method gets called by my minecraft plugin while initializing
SPLi_Main_Main.onEnable(ThePlugin); //This is the call of the init method of lavidefaultlib onEnable (This produces the exyeption, that the class SPLi_Main_Main is not found)
}
}
Your code has multiple issues, which are against spigot’s documentation.
The spigot onEnable()
method isn’t like that
In your plugin.yml
file (Documentation), you should put the direction to your main class. This main class should extends JavaPlugin
. It’s not a static call but an instance one. If you don’t know what is static, check here.
So, your class will more be like this:
package com.Lavi.init;
import com.lavi.SPLi_Main_Main;
public class FileInit extends JavaPlugin {
@Override
public void onEnable() {
SPLi_Main_Main.onEnable(this); // this = the actual object
}
}
The this
parameter refer to the instance of the actual “FileInit”
Running on spigot
On your maven project, you are importing a file. This file is used to compile, but it’s not included in the built file. You have to put the file imported on your server (mostly if the other file is another plugin), or you have to shade it with maven shade plugin.
Convention
In general, the package is com/fr/de/io/etc
.pseudo/enterprise/etc
.projectname
. I think you project is not called “Init”. Also, to easily find what is the package or not, we write all package as lower case, start class with an upper case (you did it), don’t use _
for class names etc.
It’s the Camel Case.
It’s a suggestion. It’s easier to others readers (and even you in few months/years) to understand the code, but it’s not necessary.
3