Reputation: 11
As part of solving GIT vulnerability issue, i upgraded splunk-library-javalogging from 1.7.0 to 1.11.1.
But when i deployed this to my k8s cluster i am getting error like java.lang.NoClassDefFoundError: Could not initialize class okhttp3.OkHttpClient
I changed my deployment version to previous one, then it works fine. Not sure why changing version to 1.11.1 gives me this error
This is working
<dependency>
<groupId>com.splunk.logging</groupId>
<artifactId>splunk-library-javalogging</artifactId>
<version>1.7.0</version>
</dependency>
Below is not working
<dependency>
<groupId>com.splunk.logging</groupId>
<artifactId>splunk-library-javalogging</artifactId>
<version>1.11.1</version>
</dependency>
And i have to upgrade to 1.11.1 or higher to resolve GIT vulnerability issue. I have read many solutions but i did not find any answer helpful. This is a maven project and i am running it on java 8.
Also, running jar file in my local doesn't give the error. Issue is only in k8s cluster
Update 4th Mar 2022 i explicitly declared version after reading some solution on the internet like below
<mockwebserver.version>4.7.2</mockwebserver.version>
<okhttp3.version>4.7.2</okhttp3.version>
But now i am getting slighly different error
org.springframework.boot.SpringApplication|Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'okHttpClientBuilder' defined in class path resource [org/springframework/cloud/commons/httpclient/HttpClientConfiguration$OkHttpClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [okhttp3.OkHttpClient$Builder]: Factory method 'okHttpClientBuilder' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class okhttp3.internal.Util
Earlier error was org.springframework.boot.SpringApplication|Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'okHttpClientBuilder' defined in class path resource [org/springframework/cloud/commons/httpclient/HttpClientConfiguration$OkHttpClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [okhttp3.OkHttpClient$Builder]: Factory method 'okHttpClientBuilder' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class okhttp3.OkHttpClient
Upvotes: 0
Views: 13666
Reputation: 1906
A jar cannot file express which other jars it depends on in a way that the jvm will understand,the runtime will not detect unfulfilled dependencies until it needs to access them. this will lead to a noclassdeffounderror crashing the running application, well known as Jar-Hell problem, there are many maven goals (such as mvn dependency:analyze
)and plugins can help you to have dependency analyze, or on language level you can adopt modular programing to prevent this kind of exception but generally using <optional>
or <exclusion>
tags on direct dependencies that request the transitive dependency is the most available choice to have version and duplicate dependency control .
Upvotes: 2