DataDog/datadog-api-client-java

NoClassDefFoundError: jakarta/ws/rs/core/GenericType upgrading past 2.0.0

internetstaff opened this issue · 24 comments

2.0.0 works fine, but upgrading to 2.1.0 or 2.2.0 throws ClassNotFoundException looking for jakarta.ws.rs.core.GenericType

new LogsApi(ApiClient
        .getDefaultApiClient()
        .setApiKey(x);

Hi,

Can you detail your environment a bit? What's your java version? Do you use maven? Which jars do you install? Thanks.

We're on Java 17, Maven 3.8.5. We are only explicitly installing datadog-api-client.

It's most likely an issue with the upgrade, as that dependency should have been upgraded when going from 2.0 to 2.1. Can you try bumping jakarta.ws.rs-api from jakarta.ws.rs?

Bumping jakarta.ws.rs-api to 3.1.0 leads to NoClassDefFoundError: javax/ws/rs/core/Configurable

2.3.0 has the same issue, fwiw.

For me, datadog-api-client is pulling in jersey 2.3.5, which pulls in jakarta.ws 2.1.6. This seems odd since 2.1.0 says it upgrades to jersey 3.x?

Right we do depend on jersey 3:

<jersey-version>3.0.4</jersey-version>
. It's weird that it's getting 2 in your environment.

encountered the same problem: in our spring-boot 2.7.4 app the property jersey.version gets set to 2.35 via spring-boot-dependencies. So i assume this is caused by an override for the maven property. When manually setting the jersey.version to 3.0.4 everything works fine, but is only a workaround because then the jersey version is pinned to that version.

@internetstaff are you also using spring-boot?

Same problem here.

same issue here

Can you try putting this in the pom:

<properties>
    <jersey-version>3.0.4</jersey-version>
</properties>

adding that gets me
Caused by: java.lang.NoClassDefFoundError: jakarta/ws/rs/core/Configuration

Oh okay: setting jersey-version does not fix it, but setting jersey.version works. So it it's not the property getting overriden, which would have been strange. It's the jersey-bom in dependencyManagment from spring-boot-dependencies:

  <dependencyManagement>
    ...
      <dependency>
        <groupId>org.glassfish.jersey</groupId>
        <artifactId>jersey-bom</artifactId>
        <version>${jersey.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    ...
    </dependencyManagement>

and so by setting jersey.version the version is defined (defaults to 2.35 in spring-boot-deps).
output of mvn dependency:tree -Dverbose shows

...
[INFO] +- com.datadoghq:datadog-api-client:jar:2.3.0:compile
[INFO] |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile (version managed from 2.1.0; scope not updated to compile)
[INFO] |  +- org.glassfish.jersey.core:jersey-client:jar:2.35:compile (version managed from 3.0.4)
...

But I couldn't figure out a smart way of overriding the dependencyManagment version in datadog-api, even when setting it there (in dependencyManagment section) the transitive dependency from the parent is still preferred.

Does that mean that spring-boot depends on jersey-client 2? Can you try maybe using the shaded jar distribution of the client, as it should contain the correct version of the library?

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.

Hi All,

I am facing couple of issues implementing Datadog custom metrics api
With datadog-api-client 2.4 version:
NoClassDefFoundError: javax/ws/rs/core/Configurable is thrown.

As per earlier comments when i tried to revert the datadog-api-client version 2.0, getting below error:
java.lang.NoSuchMethodError: 'void javax.ws.rs.core.MultivaluedMap.addAll(java.lang.Object, java.lang.Object[])'
at org.glassfish.jersey.client.ClientRequest.accept(ClientRequest.java:280)
at org.glassfish.jersey.client.JerseyInvocation$Builder.accept(JerseyInvocation.java:242)
at org.glassfish.jersey.client.JerseyInvocation$Builder.accept(JerseyInvocation.java:165)

Is there a workaround to fix it?
I am using Java 11 and it's a spring boot application.

Hello,

I have the same issue with datadog-api-client 2.6 and 2.7.
Java 11 + SpringBoot 2.5.8

Nicolas

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.

Hi, I see new version of the Api was released, but this issue persist. Can someone look into that, or at least specify here which versions of Jakarta are required?

Have you tried the shaded jar artifact?

Same problem here even trying 2.10.0 but it throws the error since 2.1.0 onwards

Exception in thread "main" java.lang.NoClassDefFoundError: jakarta/ws/rs/client/InvocationCallback
	at com.dersuzala.movieme.MonitorCreatetExample.main(MonitorCreatetExample.java:15)
Caused by: java.lang.ClassNotFoundException: jakarta.ws.rs.client.InvocationCallback
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 1 more

Java19, SpringBoot 2.7.4
Any help?

Hi, have you tried the shaded jar artifact?

In looking at this issue, what would the shaded jar artifact configuration look like in Maven?

Getting the following error when trying to use DD-Agent v2.10. Tried adding Jakarta deps and using Java 19 and Spring Boot 2.7.4. ANy ideas?
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.datadog.api.client.ApiClient]: Factory method 'datadogApiClient' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/ws/rs/core/Configurable 11:43:07 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.24.jar:5.3.24] 11:43:07 at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.24.jar:5.3.24] 11:43:07 ... 90 common frames omitted 11:43:07 Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/core/Configurable 11:43:07 at com.datadog.api.client.ApiClient.getDefaultClientConfig(ApiClient.java:1760) ~[datadog-api-client-2.10.0.jar:na] 11:43:07 at com.datadog.api.client.ApiClient.buildHttpClient(ApiClient.java:1739) ~[datadog-api-client-2.10.0.jar:na] 11:43:07 at com.datadog.api.client.ApiClient.<init>(ApiClient.java:521) ~[datadog-api-client-2.10.0.jar:na] 11:43:07 at com.datadog.api.client.ApiClient.<init>(ApiClient.java:511) ~[datadog-api-client-2.10.0.jar:na] 11:43:07 at com.datadog.api.client.ApiClient.getDefaultApiClient(ApiClient.java:475) ~[datadog-api-client-2.10.0.jar:na]

For anyone who finds this error, here is the solution:
<dependency> <groupId>com.datadoghq</groupId> <artifactId>datadog-api-client</artifactId> <version>2.10.0</version> <classifier>shaded-jar</classifier> <scope>compile</scope> </dependency>

Documented in #1750