Steps to reproduce:
java -jar hello-world.jarException thrown at startup is
Error: Could not find or load main class HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
Removing docker-java from compile dependencies fixes the issue.
Example build.gradle
dependencies {
compile(
"com.github.docker-java:docker-java:3.0.14"
)
}
task helloWorld(type: Jar) {
manifest {
attributes 'Main-Class': 'HelloWorld'
}
baseName = 'hello-world'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
Reproduced with jdk8, jdk9, jdk10
Tested with docker-java versions 3.0.6, 3.0.14, 3.1.0-rc-4
A workaround we've found for this is to build a skinny jar with the dependencies on the classpath rather than bundling everything into a fat jar.
I have exactly the same issue. After including the docker-java as a compile dependency java can't load my main class from the fat jar with a SecurityException "Invalid signature file digest for Manifest main attributes". Actually the same happens when I try to add the docker-client library. The reason was that the library's signature files were copied into the META-INF of my fat jar and it broke class loading of my main class. Here is the fix:
jar {
manifest {
attributes(
"Main-Class" to "sandbox.MainKt"
)
}
from(configurations.compile.get().map { if (it.isDirectory) it else zipTree(it) })
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
}
@sedovalx I'm facing this same exact problem but I'm new to this, so I'm not sure how would I go about using your fix. Could you elaborate a little on how to implement your fix? Thanks in advance
@dwgabriel the code fragment above is from my Gradle build script. It describes the configuration of the jar task that can be run with ./gradlew jar. The task assembles an executable jar file that can be executed with java -jar my-app.jar.
Build scripts in Gradle typically named as build.gradle (if written in Groovy) or build.gradle.kts (in case of Kotlin).
Still broken in 3.2.6, same steps to reproduce, add dep. docker-java, build a fat jar, run with java -jar fat.jar:
dependencies {
...
implementation("com.github.docker-java:docker-java:3.2.6")
}
tasks.withType<Jar> {
manifest { attributes["Main-Class"] = "com.company.application.Main" }
configurations["compileClasspath"].forEach { file: File ->
from(zipTree(file.absoluteFile))
}
}
Is an obscure workaround enough to consider this issue closed?
Most helpful comment
I have exactly the same issue. After including the
docker-javaas a compile dependencyjavacan't load my main class from the fat jar with a SecurityException "Invalid signature file digest for Manifest main attributes". Actually the same happens when I try to add thedocker-clientlibrary. The reason was that the library's signature files were copied into the META-INF of my fat jar and it broke class loading of my main class. Here is the fix: