docker-java / docker-java

Java Docker API Client
Apache License 2.0
2.91k stars 1.05k forks source link

Fails under a Jakarta ecosystem #2203

Open GregJohnStewart opened 1 year ago

GregJohnStewart commented 1 year ago

Hello, I am trying to use this utility with Quarkus 3.x, which has made the swap over to the new(er) Jakarta EE top-level-package, as opposed to the Javax one. This results in the following errors, as javax implementations aren't available:

Caused by: 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)
    at com.ebp.openQuarterMaster.plugin.moduleInteraction.service.VoiceSearchService.getDockerClient(VoiceSearchService.java:31)
    at com.ebp.openQuarterMaster.plugin.moduleInteraction.service.VoiceSearchService.init(VoiceSearchService.java:37)
Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/core/Configuration

    at com.ebp.openQuarterMaster.plugin.moduleInteraction.service.VoiceSearchService_Bean.doCreate(Unknown Source)
    at com.ebp.openQuarterMaster.plugin.moduleInteraction.service.VoiceSearchService_Bean.create(Unknown Source)
    at com.ebp.openQuarterMaster.plugin.moduleInteraction.service.VoiceSearchService_Bean.create(Unknown Source)
    at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:113)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:37)
    at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:34)
    at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:32)
    at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
    at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:34)
    at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:21)
    at com.ebp.openQuarterMaster.plugin.moduleInteraction.service.VoiceSearchService_ClientProxy.arc$delegate(Unknown Source)
    at com.ebp.openQuarterMaster.plugin.moduleInteraction.service.VoiceSearchService_ClientProxy.getCurImageVersion(Unknown Source)
    at com.ebp.openQuarterMaster.plugin.LifecycleBean.onStart(LifecycleBean.java:26)
    at com.ebp.openQuarterMaster.plugin.LifecycleBean_Observer_onStart_9125660855440f4a7a908f26c4da411e22e898d6.notify(Unknown Source)
    at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:346)
    at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:328)
    at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:82)
    at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:155)
    at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:106)
    at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(Unknown Source)
    at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(Unknown Source)
    ... 13 more
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.Configuration
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.Configuration

    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
    at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:516)
    at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:466)
    ... 38 more

Are there plans to update to the new(er) packaging scheme? It should be a simple matter of find and replace all javax strings with jakarta, unless something more advanced is going on.

Edit:: I have since found the documentation on the transports. However, a couple things:

  1. Why isn't a more widely compatible/maintained/better option the default?
  2. Is there a way to configure one of the transports using the same config as the default, i.e, not have to manually configure it? I'm just trying to connect to the standard unix:///var/run/docker.sock file, and the docs aren't super clear as to how to just go the simple route. (Looking to go the ZeroDep route)
GregJohnStewart commented 1 year ago

Figured out this particular issue.

Still have questions, but for posterity and so this code doesn't only exist on Twitter:

ZerodepDockerHttpClient client = new ZerodepDockerHttpClient.Builder()
    .dockerHost(URI.create("unix:///var/run/docker.sock"))
    .build();
PetrusHahol commented 9 months ago

Hi @GregJohnStewart , would you share how you figured out the original issue?

GregJohnStewart commented 9 months ago

The original issue was due to JEE packaging changes, and the default connector(s) using the older packages (javax).

By switching to the zero dependency connector, those libs aren't pulled in and works fine. I was only able to find that code example on a tweet, nothing in documentation.

bsideup commented 9 months ago

nothing on documentation

PTAL at https://github.com/docker-java/docker-java/blob/main/docs/getting_started.md#instantiating-a-dockerhttpclient and especially https://github.com/docker-java/docker-java/blob/main/docs/transports.md . Also note that the library will print a warning when the default (Jersey) transport is used (for backward compatibility)

GregJohnStewart commented 9 months ago

s/nothing on documentation/no code examples for zero dep/

As you point out the docs mention zero dep, but no actual examples. (At least a few months ago)

The first link you posted was using the libs that incurred the wrath of Jakarta (a few months ago). If the libs have been updated to Jakarta since, great.