It's time for one of the theoretically most basic question ! I tried all classic and simple solutions and I'm running out of ideas.
So, my App works well when I launch it directly in my IDE but when I try to execute the fatJar (with a classical java -jar locationOfJar) I get the traditionnal "Error: Could not find or load main class w.x.y.z.App"
What I tried :
I quadruple checked that my main class is well defined in my build.gradle.kts (I give parts later) I even wrote this post with real copy/paste and changed all with "replace" to check if they are really the same name
I unzipped my jar and checked that the main-class is there with the right name
in the unzipped jar I checked that every import of the main-class is present
I verified that the .jar contains a META-INF/MANIFEST.MF, it contains 2 lines : Manifest-Version: 1.0 and Main-Class: w.x.y.z.App
when I try to run the jar (and not the fatJar) I get the error "no main manifest attribute" while the manifest is there too !
I'm sure it's a stupid mistake but I can't find it ! Do you have an idea ?
My build.gradle.kts :
plugins {
id("java")
}
java {
sourceCompatibility = JavaVersion.VERSION_17
}
tasks.register<Jar>("fatJar") {
group = "build"
archiveClassifier.set("all")
from(sourceSets.main.get().output)
dependsOn(configurations.runtimeClasspath)
from({
configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }
})
manifest {
attributes["Main-Class"] = "w.x.y.z.App"
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
dependencies {
...
}
repositories {
mavenCentral()
maven {
name = "Artifact"
url = uri(project.findProperty("mavenRepositoryUrl") as String)
credentials {
username = project.findProperty("mavenRepositoryUsername") as String
password = project.findProperty("mavenRepositoryPassword") as String
}
}
}
Start of App Class :
package w.x.y.z;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ...
public class App {
LoggerFactory.getLogger(App.class);
public static void main(String[] args) {
LOG.info("===== START =====");
...
}
}
For those wondering, the problem was solved by adding "exclude("META-INF/.SF", "META-INF/.DSA", "META-INF/*.RSA")" in the tasks.register("fatJar")
I was using a dependency that generated those kind of files next to the manifest and that was making the mess