I am trying to use the dependency Ipregistry for my Maven project but when I run the jar using the command java -jar RandomChat-1.0-SNAPSHOT.jar
, it prints out:
Exception in thread "main" java.lang.NoClassDefFoundError: co/ipregistry/api/client/cache/IpregistryCache
at fr.randomcodes.randomchat.server.ServerMain.<init>(ServerMain.java:10)
at fr.randomcodes.randomchat.server.ServerMain.main(ServerMain.java:21)
Caused by: java.lang.ClassNotFoundException: co.ipregistry.api.client.cache.IpregistryCache
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 2 more
I use the commands mvn clean package
and mvn exec:java -Dexec.mainClass="fr.randomcodes.randomchat.server.ServerMain" -s "E:\Maven\apache-maven-3.6.3\conf\settings.xml"
to compile my project. I don't seem to have any problem while compiling the project, I only have errors at runtime.
Here is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.randomcodes.randomchat</groupId>
<artifactId>RandomChat</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>RandomChat</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>co.ipregistry</groupId>
<artifactId>ipregistry-client</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>fr.randomcodes.randomchat.server.ServerMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fr.randomcodes.randomchat.server.ServerMain</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
I spent the whole day trying to find a solution, so thank you very much for anwsering!