i'm beginner with Java and I got some troubles when I run my .jar. I got a ClassNotFoundException on a netty class. It seems logic that my .jar doesn't find the netty classes.
Here is my trace :
Exception in thread "main" java.lang.NoClassDefFoundError: io/netty/channel/EventLoopGroup
at src.Main.main(Main.java:14)
Caused by: java.lang.ClassNotFoundException: io.netty.channel.EventLoopGroup
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
The compilation works fine with gradle. My main build.gradle invokes 2 build.gradle in different folders that compile the program. Here is my main build.gradle :
subprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'io.netty:netty-all:4.1.16.Final'
compile files("./lib/netty-all-4.1.16.Final.jar")
testCompile 'junit:junit:4.12'
}
}
And here is a build.gradle that is invoked by the main build.gradle, it compiles my sources.java :
apply plugin: "java"
sourceSets {
main.java.srcDir "./src/"
}
jar {
manifest.attributes "Main-Class": "src.Main"
destinationDir project.file('../Jar/')
baseName 'Server'
}
My file tree looks like this :
MyProject
--> build.gradle
--> settings.gradle
--> lib [DIR]
--> netty-all-4.1.16.Final.jar
--> server [DIR]
--> build.gradle
--> src [DIR]
--> Main.java
I don't understand why when I compile everything works, and when I run it doesn't find the netty classes.
Could you please help me ? Thank you !