How to resolve java client error Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/core/MediaType

We are trying to use initialize Platform API in our lambda function which is running outside of cumulocity environment.
We’re getting below error when trying to initialize the PlatformImpl
Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/core/MediaType

spring boot version: 3.1

Our build.gradle package
implementation ‘com.nsn.cumulocity.clients-java:java-client:1018.0.320’

code:
Platform getPlatform(TenantCredentials tenantCredential) {
try {
return new PlatformImpl(
tenantCredential.tenantUrl(),
new CumulocityBasicCredentials(tenantCredential.username(),
tenantCredential.tenant(),
tenantCredential.password(),
“”,
“”)
);
} catch (Exception e) {
logger.error(“Error creating platform”, e);
throw new RuntimeException(ExceptionMessage.C8Y_ERROR);
}
}

Hi Sandeep,

what is your java version here used to run springboot?

Are you aware of the fact that some classes have been moved from the javax namespace (used by Oracle/SUN) to the jakarta namespace (used by Apache/Jakarta)?

One idea might be to check with springboot if there is a version, which is compatible with above mentioned namespace change.

Regards,
Holger

I’m using Java 17 here, not sure about the javax/jakarta namespace. Can you please guide me on that?

Hi Sandeep,

can you explore the class PlatformImpl, if it is referencing the right imports?

Beginninng with SpringBoot 3, it should support the new JakartaEE 9.x specs with the new namespaces jakarta.* instead of the old JavaEE 8 namespaces javax.*.

You can perform a search on the web with “javax jakarta” or similar queries to determine why the namespaces had to be changed.

It might be helpful to provide more informations about the platform impl.
You might want to check with C8Y support if they already support or plan to support JakartaEE 9.x with which version of C8Y.

Addendum:
You might want to check if you need to upgrade your cumulocity client to a 10.20 version.

Regards,
Holger

Hi

this reply might help here: PlatformImpl() - #2 by Kai_Sieben, it specifically tells:

In latest versions the PlatformImpl class cannot be used directly anyway anymore, hence you should follow the Spring Boot Bean injection principles to use the SDK and its beans, e.g. just inject “InventoryApi” instead of using the “PlatformImpl” class.

There’s also a link with a sample repository that shows how to use these beans instead of the PlatformImpl class.

2 Likes