java.lang.NoClassDefFoundError: com/sun/faces/context/RequestParameterValuesMap - classnotfoundexception

I have developed a JSF 2.0/Primefaces 3.2 web application running on an amazon cloud instance.
I have been having recently lot of "NoClassDefFoundError" and don't know where to start digging. I initially thought that it has to with the Classloader but after we redeploy the application on the next day the exception disappeared.
Here are the list of jsf2.0 maven dependencies I have:
<dependecy>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
Here is the exception I recently got:
java.lang.NoClassDefFoundError:
com/sun/faces/context/RequestParameterValuesMap at
com.sun.faces.context.ExternalContextImpl.getRequestParameterValuesMap(ExternalContextImpl.java:347)
at
org.primefaces.renderkit.SelectManyRenderer.decode(SelectManyRenderer.java:39)
at
javax.faces.component.UIComponentBase.decode(UIComponentBase.java:787)
at javax.faces.component.UIInput.decode(UIInput.java:757) at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1181)
at javax.faces.component.UIInput.processDecodes(UIInput.java:662)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
org.primefaces.component.layout.Layout.processDecodes(Layout.java:238)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
org.primefaces.component.layout.Layout.processDecodes(Layout.java:238)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
Any help on this will be appreciated.
Thanks

After some research I believe this is a bug in Primefaces 3.2 but not sure. So I upgraded to 3.3.1 and upgraded also my mojarra to 2.1.14. I am not having this issue currently.

Related

Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup

I am currently playing with some proof-of-concept work in Spring Boot and GCP data storage.
My pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-data-datastore</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
Issue: Spring Boot fails to start
When I attempt to launch the application, I get:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:251)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:264)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)
What I tried
I tried adding the Actuator dependency.
But that did not do the trick.
I cannot figure out what dependency I am missing. I see the class definition here in 5.3.0-M2 documentation, but I'm not sure what dependency it exists in.
I also tried adding following metrics dependencies:
spring-cloud-gcp-starter-metrics
spring-metrics
spring-cloud-stream-metrics
I searched in findjar.com with no luck.
I wouldn't mind disabling it as well if that is possible.
Update:
I added:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.1</version>
</dependency>
Which gives me a new error:
An attempt was made to call a method that does not exist. The attempt
was made from the following location:
org.springframework.boot.SpringApplication.run(SpringApplication.java:324)
The following method did not exist:
'void org.springframework.context.ConfigurableApplicationContext.setApplicationStartup(org.springframework.core.metrics.ApplicationStartup)'
The method's class,
org.springframework.context.ConfigurableApplicationContext, is
available from the following locations:
...
Action:
Correct the classpath of your application so that it contains a
single, compatible version of
org.springframework.context.ConfigurableApplicationContext
I was able to solve this by downgrading Spring Boot:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
Guess it's just not compatible with 2.4.0 yet.
Specifically I also had to ensure that I used 2.3.3.RELEASE and not anything more recent due to other issues I ran across.
I don't have the spring-cloud dependency, but when upgrading to Spring Boot 2.4 from 2.3 I got the same error.
Exception in thread "main" java.lang.NoClassDefFoundError:
org/springframework/core/metrics/ApplicationStartup
Per conversation in this thread (https://github.com/spring-projects/spring-boot/issues/24880) I upgraded to Spring Framework 5.3.3 and it fixed the problem.
I had the same issue caused by an old version of spring-context JAR file loaded instead of the appropriate version.
Ensure that there were no reminiscence of old libraries in your classpath.
I had a similar issue, and it was resolved by adding the following maven dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.3.8</version>
</dependency>
I was having the same issue but with:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.9.RELEASE</version>
<scope>test</scope>
</dependency>
And the error disappeared after I upgraded to:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.3</version>
<scope>test</scope>
</dependency>
May this help, upgrade spring-cloud to the latest version.
This works for me when I faced your first error :
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
See the twitter thread here, thanks to Stéphane and Arnaud for the help.
I had the same problem, but that was caused by spring-security-ldap that i also import in version 5.4.x
Upgrade spring-security-ldap to version 5.5.0 solved the problem for me.
I had this issue when adding a Spring Boot test to a library for the first time. In my case, the library did not have a Spring Boot application.
This did the trick:
#SpringBootApplication
public class TestApplication {
public static void main(final String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
Using only spring-boot-starter-test as a Spring dependency.
Check if another dependency doesn't have dependency to spring-core with older version
May this will help someone, who is facing this error.
=> Error should look like this:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
at org.springframework.context.support.AbstractApplicationContext.<init>(AbstractApplicationContext.java:229)
at org.springframework.context.support.GenericApplicationContext.<init>(GenericApplicationContext.java:112)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:67)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:91)
Solution to the Problem:-
Go to Project folder\ Right click\ Maven\ Update maven project.
Check your Spring version (pom.xml-> view the properties).
Change the Spring version to an older/new version..Otherwise use this
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<spring.version>5.2.0.RELEASE</spring.version> <!--add this version-->
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework</groupId> <!-- sql dependency for jdbc-->
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
After adding above things, Save it(Please wait for the code to build..).
Run your Program
All The Best Guys, Let's Move Togther
I had the same Spring Boot ClassNotFoundException ApplicationStartup issue, the solution was for me to ensure that the spring boot version in my gradle plugin is the same than the dependencies in my build.gradle.kts like:
plugins {
id("org.springframework.boot") version "2.5.3"
...
}
dependencies {
implementation("org.springframework.boot:spring-boot:2.5.3")
...
}

Java 8 to Java 11 migration issues with JAXB API

We are in process of migrating our projects from Java 8 to Java 11. One of the APIs is dependent on a library that utilizes JAXB. As we know JAXB was removed from JAVA 11 we started to include the JAXB dependencies in the POM of the library.
<!-- https://mvnrepository.com/artifact/jakarta.xml.bind/jakarta.xml.bind-api -->
<!-- API -->
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<!-- Runtime -->
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
All works fine when we run the API project with
mvn spring-boot:run
However when the API is deployed in QA servers and is started using a start script with -
java -jar Sample-api-3.0.0-SNAPSHOT.jar
The API throws the following error when invoking the library that is dependent on JAXB -
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:269)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:412)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
at com.eoriginal.ecore.client.documents.SearchDocumentHistoryAPI$RequestParameters.toMap(SearchDocumentHistoryAPI.java:344)
... 14 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:267)
UPDATE :
I added the Maven Shade plugin to generate the JAR with all the dependencies but when the line of code is executed to create the JAXBContext the error still persists -
JAXBContext jaxbc = JAXBContext.newInstance(new Class[]{Abc.class});
JAXB needs javax.activation module, which became jakarta.activation after rebranding to JakartaEE. Inlcuding this dependency should help:
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.0.0</version>
</dependency>
Add this dependency to POM:
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>

Using ElasticSearch and Lucene getting Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_7_2_1

I am using the following dependencies-
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>7.2.0</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-join</artifactId>
<version>7.1.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.2.3</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>6.2.3</version>
</dependency>
Get the exception as
Exception in thread "main" java.lang.NoSuchFieldError: LUCENE_7_2_1
at org.elasticsearch.Version.<clinit>(Version.java:152)
at org.elasticsearch.common.logging.DeprecationLogger.<clinit>(DeprecationLogger.java:159)
at org.elasticsearch.common.ParseField.<clinit>(ParseField.java:35)
at org.elasticsearch.client.RestHighLevelClient.lambda$getDefaultNamedXContents$47(RestHighLevelClient.java:673)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.HashMap$EntrySpliterator.forEachRemaining(HashMap.java:1691)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.elasticsearch.client.RestHighLevelClient.getDefaultNamedXContents(RestHighLevelClient.java:674)
at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:215)
at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:200)
at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:192)
Know there are similar questions and it is about lucene dependency issue. But i am not able to get the dependencies right. Any help is appreciated. Thanks
You are using three versions of lucene here, 7.1.0, 7.2.0, and Elasticsearch 6.2.3 would be at version 7.2.1.
You should use the same version for all of these, so change the version of your lucene-core and lucene-join dependencies to 7.2.1.

Maven embedded deploy not working with org.apache.httpcomponents.httpclient version 4.4

Within my application I have to (mvn) deploy artifacts programmatically. I do this with the help of the maven-embedder artifact and some really simple code:
MavenCli client = new MavenCli();
int result = client.doMain(new String[] { "deploy" }, "C:/some/path/to/my/pom", System.out, System.out);
To be able to do this, I had to add the following dependencies to my pom:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.2.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-wagon</artifactId>
<version>1.0.2.v20150114</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<version>2.8</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3</version>
</dependency>
Problem is, when I change the version of httpclient to version 4.4 (the most recent one), I get the following error when trying to deploy:
4840 [main] WARN Sisu - Error injecting: org.apache.maven.wagon.providers.http.HttpWagon
java.lang.NoClassDefFoundError: org/apache/http/ssl/TrustStrategy
at java.lang.ClassLoader.defineClass1(Native Method)
...
Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.TrustStrategy
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
... 72 more
Anybody got an idea, why deploy works fine with version 4.3.x of org.apache.httpcomponents.httpclient and fails with version 4.4?
I suspect that the version of HttpCore? which HttpClient is based upon, still resolves to 4.3.x. Try explicitly setting it to 4.4
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>

Could not initialize class org.apache.cxf.staxutils.StaxUtils

I'm developing an application using Spring/Maven and I'm experiencing a problem with a dependency. Everything was working but when I added a dependency to Spring-WS, my tests stopped working.
Here is the stacktrace I have, leading to a Failed to load ApplicationContext
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.cxf.staxutils.StaxUtils
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:256)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:203)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:199)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:98)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.mycompany.webservice.documentservice.client.DocumentServiceService.<init>(DocumentServiceService.java:61)
at com.mycompany.service.implementation.DocumentService.<init>(DocumentService.java:121)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
And here is the new dependencies :
<!--
Spring WS
-->
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>${spring-ws.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<version>${spring-ws.version}</version>
</dependency>
I think there is a conflict with CXF dependencies but can't find where :
<!--
Web Service
-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-core</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
Here are the conflicts, but when I add an exclusion the problem still occurs
Thanks for the help.
Ok I fixed the issue by doing the following :
Upgrade from CXF 2.7.6 to 2.7.7
Add dependency to
<dependency>
<groupId>com.sun.xml.stream</groupId>
<artifactId>sjsxp</artifactId>
<version>${sjsxp.version}</version>
</dependency>
Can't explain why but the tests run well and the application too.

Resources