'Could not find or load main class' when running jar containing docker-java as dependency
See original GitHub issueSteps to reproduce:
- Create basic gradle project with docker-java as a compile dependency
- Add a simple HelloWorld main class
- Run the gradle jar task
java -jar hello-world.jar
Exception 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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Java – “Could Not Find or Load Main Class” Error | Baeldung
Occasionally when we run a Java program, we might see “Could not find or load main class.” It's easy to guess the reason:...
Read more >Could not find or load main class with a Jar File - Stack Overflow
I got it working like this: TestClass.Java package classes; public class TestClass { public static void main(String[] args) { System.out.println("Test"); } }.
Read more >Java Guide: How to Fix "Could not find or load main class"
The Java “Could not find or load main class” error is thrown when the JVM fails to find or load the main class...
Read more >Error: Could not find or load main class in Java [Solved]
Error: Could not find or load main class HelloWorld comes when you are trying to run your Java program using java command with...
Read more >Here's How to Fix the "Could Not Find or Load Main Class ...
The classpath is the file path where the JRE (Java runtime environment) searches for the classes and other resource files to run the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:@dwgabriel the code fragment above is from my Gradle build script. It describes the configuration of the
jartask that can be run with./gradlew jar. The task assembles an executable jar file that can be executed withjava -jar my-app.jar.Build scripts in Gradle typically named as
build.gradle(if written in Groovy) orbuild.gradle.kts(in case of Kotlin).