Encountered a NoClassDefFoundError when building with Docker Java API on a spring boot "3.2.1" Kotlin 1.9.21 project
java.lang.NoClassDefFoundError: javax/ws/rs/core/Configuration
at com.github.dockerjava.jaxrs.JerseyDockerHttpClient$Builder.build(JerseyDockerHttpClient.java:124)
at com.github.dockerjava.core.DockerClientBuilder.build(DockerClientBuilder.java:106)
...
Added the javax.ws.rs-api dependency to my .kts file:
implementation("javax.ws.rs:javax.ws.rs-api:2.1.1")
Encountered a LinkageError related to ClientBuilder.
java.lang.LinkageError: ClassCastException: attempting to cast jar:file:/home/alkaphreak/.gradle/caches/modules-2/files-2.1/javax.ws.rs/javax.ws.rs-api/2.1.1/d3466bc9321fe84f268a1adb3b90373fc14b0eb5/javax.ws.rs-api-2.1.1.jar!/javax/ws/rs/client/ClientBuilder.class
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:81)
at com.github.dockerjava.jaxrs.JerseyDockerHttpClient.<init>(JerseyDockerHttpClient.java:257)
...
Build Script (build.gradle.kts):
// Relevant parts of the build script
dependencies {
// Other dependencies...
implementation("com.github.docker-java:docker-java:3.3.4")
implementation("com.github.docker-java:docker-java-transport-httpclient5:3.3.4")
implementation("javax.ws.rs:javax.ws.rs-api:2.1.1")
}
Tried using a resolutionStrategy to force the version without success.
// Apply a resolution strategy to force a single version of the dependency
configurations.all {
resolutionStrategy {
// Force usage of a specific version of 'javax.ws.rs-api'
force("javax.ws.rs:javax.ws.rs-api:2.1.1")
}
}
I'm unable to resolve the LinkageError after adding the javax.ws.rs-api dependency. If anyone has insights or suggestions on how to fix this issue, please advise.
PS : Opened an issue here too : https://github.com/docker-java/docker-java/issues/2284#issuecomment-1871987626
To make it work, we can replace the code :
private fun dockerClient(): DockerClient = DockerClientBuilder
.getInstance()
.build()
By :
private fun dockerClient(): DockerClient = DockerClientBuilder
.getInstance()
.withDockerCmdExecFactory(NettyDockerCmdExecFactory())
.build()
Note that withDockerCmdExecFactory
is deprecated. I will try to improve that.
Source : https://github.com/docker-java/docker-java/issues/2284#issuecomment-1873776989