ClassNotFoundException in Hibernate - java

I am getting the following error when I am trying to run my J2EE project. The same project was working before and I started getting this exception now. I am sure that all class are there along with their mapping files.
If I remove mapping of jobtitle from my hibernate.cfg.xml in the project, it is running.
java.lang.ExceptionInInitializerError
hrm.dao.HibernateUtil.<clinit>(HibernateUtil.java:28)
hrm.dao.AbstractDAO.<init>(AbstractDAO.java:29)
hrm.dao.JobSpecificationDAO.<init>(JobSpecificationDAO.java:22)
hrm.actions.JobSpecificationAction.execute(JobSpecificationAction.java:53)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
java.lang.ClassNotFoundException: hrm.dao.Jobtitle

java.lang.ClassNotFoundException: hrm.dao.Jobtitle
means you do indicate a mapping in your hibernate.cfg.xml, but a mapping to a class which is not in the classpath of the j2ee project.

Related

java.lang.ClassNotFoundException: org.hibernate.HibernateException while deploying EAR [duplicate]

This question already has an answer here:
Not able to deploy EAR file
(1 answer)
Closed 6 years ago.
I am developing a web module in struts2 framework and ejb module in eclipse with hibernate as ORM framework.
Every time when I modify my ejb module I have to package it into jar and include it in my web module /WEB-INF/lib folder in order to run my whole application.
Though the application worked fine in this way but it was really time consuming. So I tried to map them in a EAR module. But when I try to run EAR module.
It gives below exceptions
2016-12-24 13:23:43,992 ERROR [org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler] (default task-4) Exception occurred during processing request: WFLYEJB0442: Unexpected Error: javax.ejb.EJBException: WFLYEJB0442: Unexpected Error
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:184)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:277)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:47)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/HibernateException
at com.ebs.persistence.dao.UserDao.<clinit>(UserDao.java:16)
at com.ebs.business.service.UserAuthorisationBusinessService.getUserProfile(UserAuthorisationBusinessService.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException from [Module "deployment.EBS.ear.EBS-ejb.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
... 179 more
Below is where I suspect to get the exception
private static SessionFactory sessfct = SessionFactoryGenerator.getSessionFactory();
It seems to be some issue with classloader.Somehow it is not able to load hibernatecore.jar. Earlier it use to work fine with same set of jars when EAR was not in the picture. I am new to EAR. Below is the structure of application.xml
<module>
<web>
<web-uri>EBS-web.war</web-uri>
<context-root>EBS-web</context-root>
</web>
</module>
<module>
<ejb>EBS-ejb.jar</ejb>
</module>
I also tried including all the jars in EAR lib folder but no success was achieved
I am developing a web module in struts2 framework and ejb module in
eclipse with hibernate as ORM framework. Every time when I modify my
ejb module I have to package it into jar and include it in my web
module /WEB-INF/lib folder in order to run my whole application.
With an Eclipse plugin as WTP, you should not have this problem.
I also tried including all the jars in EAR lib folder but no success
was achieved
If you place the JARs in the EAR, they should be in the APP-INF/lib folder at the root of the EAR.
Besides, you could use a build tool as Maven or Gradle. It could ease your job of packaging.

java.lang.NoSuchFieldError: APPLICATION_CONTEXT_ID_PREFIX in Eclipse project [duplicate]

I am receiving this error on running my project and the result is 404 ultimately. The project is made on Spring framework.
I read a lot of posts and found that there is either a mix up of jars or extra jars. Following which I tried to organize my jars. The following list is what I have in my build path:
antlr-2.7.6.jar
asm.jar
asm-attrs.jar
cglib-2.2.jar
commons-beanutils-1.7.0.jar
commons-collections-3.1.jar
commons-digester-1.8.jar
commons-email-1.0.jar
commons-fileupload-1.1.1.jar
commons-io-1.2.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
displaytag-1.0-b3.jar
dom4j-1.6.1.jar
ehcache-1.1.jar
hibernate3.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate-validator-4.0.2.GA.jar
hsqldb.jar
itext-2.1.3.jar
javassist-3.12.0.GA.jar
jdom.jar
jstl-1.2.jar
jta-1.1.jar
log4j-1.2.14.jar
msbase.jar
mssqlserver4v65.jar
msutil.jar
mysql.jar
mysql-connector-java-5.1.15-bin.jar
ojdbc14.jar
persistence-api-1.0.jar
poi-3.0-alpha2.jar
servlet-2.3.jar
slf4j-api-1.6.6.jar
slf4j-log4j12-1.5.6.jar
slf4j-simple-1.6.6.jar
spring-asm-3.0.3.RELEASE.jar
spring-beans-3.0.3.RELEASE.jar
spring-context-3.0.3.RELEASE.jar
spring-core-3.0.3.RELEASE.jar
spring-expression-3.0.3.RELEASE.jar
spring-hibernate3-2.0.8.jar
spring-web-3.0.3.RELEASE.jar
spring-webmvc-3.0.3.RELEASE.jar
sqljdbc4.jar
standard.jar
tree.jar
validation-api-1.0.0.GA.jar
wloracle.jar
wlsqlserver.jar
Here goes the stacktrace
SEVERE: Error loading WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader#ca2dce
org.springframework.web.servlet.DispatcherServlet
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4364)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
at org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:315)
at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148)
at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:420)
at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1433)
at org.apache.jasper.compiler.Parser.parse(Parser.java:133)
at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:153)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
I have deleted many jars, which I thought, are repetitive.
My question is whether all these jars are exactly enough or are there duplicates?
Please help, this 404 is killing me...
You have a lot of duplicated jars there:
antlr
jta
mysql-connector
javassist
mssqlserver
I would make sure you only have one of each before continuing, work out which version you need and include that one.
If you are not sure how to do this, let us know how you are importing your dependencies.
It would also be helpful to see the stacktrace you are seeing and a simplified Spring context that causes the error.
If you look at this question: JasperException: absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved
You need to make sure you have the right version of JSTL, maybe once you remove the duplicate JSTL it may fix that error.
My guess would be deleting spring.jar and spring-1.2.6.jar ; they conflict with spring*3.0.3.RELEASE.jars
And my two cents would be using maven when working with spring framework.

File reported as missing but it is not

I am working on a java web application using struts that someone else wrote and I was getting errors about an import that was missing in some files so I looked around the project folders and found the file among the jsp files which seemed strange. So, I copied the file into the relevant package and the errors went away. When I went to run the program again on Tomcat I got this error:
org.apache.jasper.JasperException: /index.jsp(3,55) File "/WEB-INF/struts-html.tld" not found
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:166)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:410)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:475)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1425)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
"/WEB-INF/struts-html.tld" still exists and hasn't been changed or moved. I decided to delete the file I moved because the program still worked without it but I still get the error and I'm not sure how I could fix this.
Edit:
So I decided to refresh the webpage and a different error showed up:
org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:168)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:132)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:162)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:356)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
The tld (tag library) files and their locations are specified in the web.xml file.
If you need new tlds, the jsp files which are using these tlds will look first in the web.xml to find info and location of the file.
In your web.xml you need to place taglib definitions right after welcome-page definitions. It worked for me.

java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session

i am trying to integrate my already working spring project with hibernate, but this is the error i am getting on start up.
EVERE: Servlet.service() for servlet [appServlet] in context with path [/TelephoneDirectory] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;] with root cause
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/classic/Session;
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:322)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:233)
at org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:457)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:393)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)
at com.emumba.telephonedirectory.repository.JdbcPersonDao.getPersonsList(JdbcPersonDao.java:36)
at com.emumba.telephonedirectory.service.SimpleDirectoryManager.getAllPersons(SimpleDirectoryManager.java:23)
at com.emumba.telephonedirectory.web.HomeController.home(HomeController.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I have googled it but all i could find was that similar problems were caused by duplicates in classpath but i have looked very closely and i dont think their are any duplicates in my classpath. (may be i am wrong.) Heres a screen shot of jars in my classpath
i am stuck, any help will be greatly appreciated
EDIT: Search for org.hibernate.SessionFactory gives
The problem is that you have hibernate-core-4.0.0.Final.jar in your classpath, but Spring 3.1 uses hibernate-core-3.6.0.Final.jar (see here Spring 3.1 artifact and dependencies).
Remove Hibernate 4.0 and put Hibernate 3.6 instead in your classpath.
BTW, there might some more such miss matches. It's better to use maven to take care of dependencies.
EDIT - some more details
In Hibernate 3.6 the interface Session was in package org.hibernate.classic whereas in Hibernate 4.0 it was moved to the package org.hibernate.
In Hibernate 3.6 the SessionFactory.openSession no longer returns an org.hibernate.classic.Session, rather it returns an org.hibernate.Session. This is a refactor that breaks client code...
If you are using Eclipse as IDE and maven as a build tool, try to check build path entries. Sometimes, old JARs are added as classpath entries which are not overridden by maven clean or update.
You would need to remove those entries.
Refer below image
Above entries should not be present in build path, since they are not overridden by maven clean.
I was having similar kind of trouble; used a different version of apache-camel-extra helped resolving the problem
compile group: 'org.apache-extras.camel-extra', name: 'camel-hibernate', version: '2.18.0'
Our application setup
gradle
apache-camel
spring
hibernate
spring-jta and atomikos
This error is caused by transitive dependency of maven managed projects. Child will be using a particular version of an artefact but the parent would fetch a later version. In my case, I had to use
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
</dependencies>
In the parent pom (i.e, I have specified the dependency version again in parent pom) to avoid this conflict.

Tomcat Restart automatically Web Application on startup, after error

I've a big trouble on tomcat.
Before explaine, let me tell is the first time I see something like this...
I'm building an application using JPA on Hibernate, Spring 3.0 and Jersey REST Framework.
When using glassfish, everything works fine, but deployng the same application on tomcat, I registered the following error code:
GRAVE: Error deploying configuration descriptor java-zero.xml
java.lang.NoClassDefFoundError: com/sun/jersey/spi/container/servlet/ServletContainer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2527)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1010)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1483)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
... 34 more
Then tomcat restarts the application and again, the same error. In an infinite loop.
Looks like a library conflict, but I really don't have any ideas on how to solve it...
Any suggestion is appreciated!
Ciao, Davide.
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer suggests that you either don't have the Jersey JAR file or you've put it in the wrong place.
If it's the former, download it here and add it to Tomcat.
If it's the latter, put it and all its dependencies in either your WEB-INF/lib, server/lib for Tomcat 5.x or lib for Tomcat 6.x. (Just one, not all.)
It works with Glassfish because they've bundled it for you. Tomcat has not.
Remove all Jersey JAR from /WEB_INF/lib folder, refresh project and again paste all JARs of Jersey library into /WEB_INF/lib. Refresh project, stop server again, deploy and run.
It looks like either jersey.jar and/or jsr311-api.jar are missing from your webapp. You might check they are in the WEB-INF/lib folder.

Categories