While i'm running maven web application in eclipse neon using tomcat server that throws an error like the followings,Help me to resolve this.
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 1 in the generated java file
The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files
You should require at least jsp 2.1 and add the required dependencies in your pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
Related
I know that there are other questions in stackoverflow talking about similar issue but here the problem is different. I am working on a spring boot project to create a service. The service exposes some APIs, also it retrieves data from another SOAP based service. I added following code to my main method
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
and the application is working just fine when I run it from eclipse and access exposed APIs. However, when I access APIs by executing FatJAR created using maven then I get following error
ERROR [http-nio-8090-exec-7] org.apache.juli.logging.DirectJDKLog: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.logging.LogFactory.getClassLoader(Ljava/lang/Class;)Ljava/lang/ClassLoader;] with root cause
java.lang.NoSuchMethodError: org.apache.commons.logging.LogFactory.getClassLoader(Ljava/lang/Class;)Ljava/lang/ClassLoader;
at org.apache.commons.logging.impl.LogFactoryImpl.getClassLoader(LogFactoryImpl.java:447)
at org.apache.commons.logging.impl.LogFactoryImpl.initDiagnostics(LogFactoryImpl.java:476)
at org.apache.commons.logging.impl.LogFactoryImpl.<init>(LogFactoryImpl.java:95)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:590)
at org.apache.commons.discovery.tools.ClassUtils.newInstance(ClassUtils.java:153)
If I remove the following line from my main method and create FatJAR
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.LogFactoryImpl");
and start the service from fatJAR and access APIs then it runs fine. But running application form eclipse and accessing APIs gives the following error
ERROR[0;39m [[34mhttp-nio-8090-exec-4[0;39m] [33morg.apache.juli.logging.DirectJDKLog[0;39m: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
org.apache.commons.discovery.DiscoveryException: No implementation defined for org.apache.commons.logging.LogFactory
at org.apache.commons.discovery.tools.DiscoverClass.find(DiscoverClass.java:404)
at org.apache.commons.discovery.tools.DiscoverClass.newInstance(DiscoverClass.java:579)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:418)
at org.apache.commons.discovery.tools.DiscoverSingleton.find(DiscoverSingleton.java:378)
at org.apache.axis.components.logger.LogFactory$1.run(LogFactory.java:45)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at org.apache.axis.components.logger.LogFactory.getLogFactory(LogFactory.java:41)
at org.apache.axis.components.logger.LogFactory.<clinit>(LogFactory.java:33)
following is the snippet from my POM.
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
The project builds, install, deploy without any issue. The error occurs only when I access the API after running the application. I search other resources they all are saying that there might be some Logging JAR conflict so I removed some dependency and added different dependencies but all the time it ends up in error either in eclipse or FatJAR.
Any help or reference for other resources are welcome.
I have a maven based project. This is how the project looks like in eclipse:
So I have separate front and back end that are packed into one EAR. The application were deployed on Weblogic 12c server but now I have to move it to Glassfish. I can deploy to Glassfish and my application is running. But, i got an error message when I invoke a method which use Primefaces UploadFile class. This is the error message:
java.lang.NoClassDefFoundError: org/primefaces/model/UploadedFile
javax.ejb.EJBException: java.rmi.ServerError: Error occurred in server thread; nested exception is:
java.lang.NoClassDefFoundError: org/primefaces/model/UploadedFile
This two dependency:
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0</version>
</dependency>
Are in both POM.xml (front and back end) And the maven dependency is in my classpath as you can see in this picture:
My question is, where should I put the Primefaces jar, to make visible for Glassfish in runtime?
You'll either need to add the dependencies to the /lib folder of Glassfish as this is where the container will check for them, or bundle them up with the deployable artifact - in your case the .ear file. As you are using maven there are a couple of plugins available that may help you e.g. the Maven Assembly or Maven Ear plugins.
-Answer based on my comment above.
I have a war and want to deploy it on a websphere application server.
The application server has slf4j, version 1.4.2 installed.
However, my application requires at least version 1.6.1.
Here's the dependency defined in my POM:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
</dependency>
I can build the application successfully, but everytime I try to launch it on the websphere server, I get the following error:
DispatcherSer E org.springframework.web.servlet.DispatcherServlet initServletBean Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in ServletContext resource [/WEB-INF/spring/timer-context.xml]: Invocation of init method failed; nested exception is java.lang.LinkageError: org.slf4j.Logger
What do I have to do so that my application uses version 1.6.1, and ignores the already installed version on the server?
Related Question: java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
I m getting the following exception while trying to deploy the war file on Weblogic 10.3.6 server.
The application is using SPring mvc.
Error loading DispatcherServlet's default strategy class [org.springframework.web.servlet.mvc.support.Def
aultHandlerExceptionResolver] for interface [org.springframework.web.servlet.HandlerExceptionResolver]: problem with class file or dependent class; nested exception is
java.lang.NoClassDefFoundError: org/springframework/web/bind/MethodArgumentNotValidException
at org.springframework.web.servlet.DispatcherServlet.getDefaultStrategies(DispatcherServlet.java:766)
at org.springframework.web.servlet.DispatcherServlet.initHandlerExceptionResolvers(DispatcherServlet.java:604)
at org.springframework.web.servlet.DispatcherServlet.initStrategies(DispatcherServlet.java:423)
at org.springframework.web.servlet.DispatcherServlet.onRefresh(DispatcherServlet.java:410)
at org.springframework.web.servlet.FrameworkServlet.onApplicationEvent(FrameworkServlet.java:752)
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:989)
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:1)
at org.springframework.context.event.GenericApplicationListenerAdapter.onApplicationEvent(GenericApplicationListenerAdapter.java:51)
at org.springframework.context.event.SourceFilteringListener.onApplicationEventInternal(SourceFilteringListener.java:97)
at org.springframework.context.event.SourceFilteringListener.onApplicationEvent(SourceFilteringListener.java:68)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:929)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
Your classpath doesn't have spring-web-x.x.x.jar, that's why the exception is. Please use Maven build tool for building your Spring MVC project. Add all the necessary dependencies in pom.xml. For spring-web 3.0.4 version, it would be
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
My ear application runs well on Tomcat 6 on local window PC, but it cannot run on Weblogic server 10.3.6 on the same PC.
Caused By: java.lang.VerifyError: (class: org/springframework/web/servlet/FrameworkServlet, method: processRequest signature: (Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V) Incompatible argument to function
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2291)
at java.lang.Class.getDeclaredFields(Class.java:1743)
at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.getFields.....
Below is part of my pom.xml which might be related to the problem.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
From your webapp's /WEB-INF/lib folder, remove all Tomcat-specific libraries like el-ri.jar, el-api.jar. It will make your webapp incompatible with containers of a different make/version resulting in this kind of errors.
For more info clear explanation see here
Possible cause 1:
java.lang.VerifyError can be the result when you have compiled against a different library than you are using at runtime.
Refer here Causes of getting a java.lang.VerifyError
Possible cause 2:
How do I import the javax.servlet API in my Eclipse project?
Specially read this paragraph
You should above all never manually copy/download/move/include the individual servletcontainer-specific libraries like servlet-api.jar, jsp-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc. It would only lead to future portability, compatibility, classpath and maintainability troubles, because your webapp would not work when it's deployed to a servletcontainer of a different make/version than where those libraries are originally obtained from.