1

I am trying to create a Docker client with the Docker Java API, but I get a ClassNotFoundException when running my code. I am following this Baeldung guide, but I am using the latest version of docker-java-api (version 3.3.3).

Maven import:

<dependency>
    <groupId>com.github.docker-java</groupId>
    <artifactId>docker-java</artifactId>
    <version>3.3.3</version>
</dependency>

Code:

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DockerClientBuilder;

public class Main
{
    public static void main(String[] args)
    {
        DockerClient dockerClient = DockerClientBuilder.getInstance().build();    
    }
}

Full Error:

Connected to the target VM, address: '127.0.0.1:59830', transport: 'socket'
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
SLF4J: Ignoring binding found at [jar:file:/Users/idelmas/.m2/repository/org/slf4j/slf4j-jdk14/1.7.36/slf4j-jdk14-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.
Exception in thread "main" java.lang.NoClassDefFoundError: com/github/dockerjava/api/command/LoadImageAsyncCmd
    at com.github.dockerjava.core.DockerClientBuilder.build(DockerClientBuilder.java:101)
    at com.proofpoint.Main.main(Main.java:14)
Caused by: java.lang.ClassNotFoundException: com.github.dockerjava.api.command.LoadImageAsyncCmd
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 2 more
Disconnected from the target VM, address: '127.0.0.1:59830', transport: 'socket'

Process finished with exit code 1
4
  • 1
    Can you try adding the docker-java-api dependency to your pom.xml as well and see if that resolves the issue? Just from a quick glance it seems that the docker-java dependency doesn't transitively include the api dependency. You may also want to comment on this GitHub issue which seems to be the same problem you're having here. Commented Aug 22, 2023 at 13:46
  • thanks for pointing out that the docker-java-api was not included with the docker-java. adding this to the pom.xml solved the problem Commented Aug 22, 2023 at 17:45
  • <dependency> <groupId>com.github.docker-java</groupId> <artifactId>docker-java-api</artifactId> <version>3.3.3</version> </dependency> Commented Aug 22, 2023 at 17:45
  • glad it solved the problem. I added the solution as an answer. Commented Aug 22, 2023 at 23:54

1 Answer 1

2

It seems that the docker-java-api dependency is not included with the docker-java dependency.

If you add this dependency to your pom.xml it should resolve the issue:

<dependency>
    <groupId>com.github.docker-java</groupId>
    <artifactId>docker-java-api</artifactId>
    <version>3.3.3</version>
</dependency>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.