Exception with ClassPathXmlApplicationContext - java

I'm working with servlet + spring. The servlet shows this exception in
ApplicationContext context = new ClassPathXmlApplicationContext("my_config.xml");
This is ecxeption text:
28.08.2013 16:27:36 org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [my_spring2] in context
with path [/test_spring2] threw exception [Servlet execution threw an
exception] with root cause java.lang.ClassNotFoundException:
org.springframework.context.support.ClassPathXmlApplicationContext at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
at main_package.my_spring.doGet(my_spring.java:34) 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:225)
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:927)
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:999)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
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)
28.08.2013 16:27:59 org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/test_spring2] has started
28.08.2013 16:28:00 org.apache.catalina.core.StandardContext reload INFO: Reloading Context with name [/test_spring2] is completed

I see that the exception you got is java.lang.ClassNotFoundException
Unless you are involved in dynamic class loading and using the Java Reflection API, chances are that the ClassNotFoundException error you are getting is not from your application code but from a referencing API. Another common problem pattern is a wrong packaging of your application code.
Check to see if all the jars are added to your classpath.
Also some jars depend on other jars for their working. In that case you will have to add those jars too !

look at the line 34 in main_package.my_spring.doGet(my_spring.java:34) and see if it is referenced from local class or from an API?
If project-> build automatically is on on your eclipse if using eclipse, then you must be having class file, else you might see errors in the explorer.
most probably the class that you are referencing is from an API, if not try add jars from your project build path.

Related

java.lang.ClassNotFoundException: org.apache.commons.dbcp2.BasicDataSource in eclipse using deployment assembly

I have two projects.
Java SE based let's say abcAPI.
Dynamic Web Project using tomcat server. let's say abc-web
I followed this tutorial automatically build and include one eclipse project into another to include abcAPI into abc-web. So that I have clear separation between these two. I included all necessary dependencies and API's in abcAPI project as well and I believe when using deployment assembly their shouldn't be any problem because underlying referencing project already has reference to it's libraries and dependencies in its libs folder.
I see no error before execution. But after the project runs and BasicDataSource is called I get this exception.
SEVERE: Servlet.service() for servlet [com.trolix.abcAPI.cbf.SrvStart] in context with path [/abc-web] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: org.apache.commons.dbcp2.BasicDataSource
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at com.trolix.abcAPI.dbcon.DBConnection.<init>(DBConnection.java:38)
at com.trolix.abcAPI.dbcon.DBConnection.getInstance(DBConnection.java:51)
at com.trolix.abcAPI.dao.DAOStart.<clinit>(DAOStart.java:19)
at com.trolix.abcAPI.controller.CtrlStart.<init>(CtrlStart.java:14)
at com.trolix.abcAPI.manager.MgrStart.<init>(MgrStart.java:14)
at com.trolix.abcAPI.cbf.SrvStart.doPost(SrvStart.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Uptil now I have tried many things as suggested by SO community i.e.
Delete Server
Clean server
Restart Eclipse
Build Code
Deploy Again
etc.
But nothing has yet worked for me. Please guide!
I got the same error using iIntelliJ IDEA, Maven, Tomcat Server. As figured out the problem was in Artifacts(The dependency was not included to WEB-INF/lib).
To fix it - open Project Structure -> Artifacts -> drag-and-drop commons-* from Available Elements to lib

Linkage error when using Elasticsearch client in Spring WebApp

I have a problem when trying to include the Elasticsearch java client in my WebApp. I have the required dependencies and I am creating the client (As a simple test) in a initializing/destroying Spring bean like so:
#Override
public void afterPropertiesSet() throws Exception {
try {
client = new TransportClient();
InetSocketTransportAddress addr = new InetSocketTransportAddress("localhost", 9300);
((TransportClient) client).addTransportAddress(addr);
}
catch(Exception e){
System.out.println(e.toString());
}
}
The corresponding destroy() will close the client.
Everything looks ok and the context starts fine however when accessing a JSP I receive the following exception:
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Fountain] threw exception [Filter execution threw an exception] with root cause
java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "javax.servlet.ServletResponseWrapper.getOutputStream()Ljavax/servlet/ServletOutputStream;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, javax/servlet/ServletResponseWrapper, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for interface javax/servlet/ServletResponse have different Class objects for the type vlet/ServletOutputStream; used in the signature
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:186)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:181)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
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:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Jan 10, 2014 10:44:46 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jsp.jsp.ajaxerror_jsp._jspService(ajaxerror_jsp.java:59)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:412)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:201)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
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:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Jan 10, 2014 10:44:46 AM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/jsp/ajaxerror.jsp]
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:412)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:201)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
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:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletR equest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jsp.jsp.ajaxerror_jsp._jspService(ajaxerror_jsp.java:130)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
... 22 more
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jsp.jsp.ajaxerror_jsp._jspService(ajaxerror_jsp.java:59)
... 25 more
Without this the context starts and will serve JSPs correctly.
Does anyone have any ideas what may be causing this? I'm assuming the elasticsearch client is using a class that the web-app required but instatiating it in a different classloader.
I've tried explicitly setting the classloader used by elastic search by using ImmutableSettings but this appears not to make any difference:
ClassLoader contextClassLoader = thread.getContextClassLoader();
try {
//thread.setContextClassLoader(ClassLoader.getSystemClassLoader());
Settings s = ImmutableSettings.settingsBuilder()
.classLoader(contextClassLoader)
.build();
Any help would be appreciated! Thanks!
Ok, managed to resolve this problem:
Get a ref to the tomcat 'common' classloader and passed this to the Elasticsearch client:
ClassLoader contextClassLoader = thread.getContextClassLoader();
try {
Settings settings = ImmutableSettings.settingsBuilder().classLoader(contextClassLoader.getParent()).build();
client = new TransportClient(settings);
A side effect of this is that the names.txt file has to be moved from the elasticSearch jar to somewhere on the 'common' classpath.
I still haven't tracked down why this issue is affecting my particular stack and not others but aim to do so and update here.
The solution is to create the elastcisearch client like this :
Settings settings = ImmutableSettings.settingsBuilder()
.put(“path.plugins”, “fakeDirectory:\\”)
.build();
TransportClient client = new TransportClient(settings);
I put a fake directory because ElasticSearch use it when it start to load all eclipse plugins but i d’ont know why !! (see org.elasticsearch.plugins.PluginsService class).

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.

ClassNotFoundException: com.mysql.jdbc.Driver. JDBC MySQL driver for web application [duplicate]

This question already has answers here:
How to install JDBC driver in Eclipse web project without facing java.lang.ClassNotFoundexception
(13 answers)
Closed 7 years ago.
So I have a .jar file for the MySQL JDBC driver, it is under my libraries source folder and I have the following code:
public static Connection getConnection() throws SQLException {
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://50.56.81.42:3306/GUEST_BOOK";
String user = "user";
String password = "pass";
conn = (Connection) DriverManager.getConnection(url, user, password);
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
return conn;
}
However, it always gives me this error:
INFO: Server startup in 645 ms
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at gbook.DbHelper.getConnection(DbHelper.java:14)
at gbook.DbHelper.getGuestBook(DbHelper.java:51)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
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:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Dec 1, 2011 1:41:05 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/JDBC-MySQL] threw exception [javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/mysql/jdbc/Connection] with root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Connection
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
at gbook.DbHelper.getGuestBook(DbHelper.java:52)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
Here's how I added the jar file. I created a lib folder and put the jar inside and then I go to configure build path in eclipse and added the jar inside the lib folder to the project.
You missed mysql-connector-j jar file in your classpath. Use "java -cp .:mysql.jar...". Ou. It's a webapp! Then put mysql jar file to WEB-INF/lib folder.
Right click Libraries ->Add JAR/Folder and choose mysql-connector-java.jar file
if you are using Apache Tomcat, you may have to add the driver to the path using "Configure Tomcat" in Java Tab.

trouble deploying .WAR to tomcat

im having trouble deploying a war file on tomcat.
i have written a webapp in netbeans on my windows machine. it all runs fine. what i want to do is deploy the application on my linux computer that is acting as my server. once the application is built, i copy the war file from the dist folder in my project directory onto a pendrive. i then copy this onto the desktop of my linux computer.
i then start tomcat and using the application manager i browse the war file to deploy, then click deploy. i get a message at the top of the browser saying 'OK'. yet if i look at my tomcat output in the terminal window i have the following error:
4/01/2011 5:09:07 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive Kingdoms.war
4/01/2011 5:09:07 PM org.apache.catalina.startup.ContextConfig init
SEVERE: Exception fixing docBase for context [/Kingdoms]
java.util.zip.ZipException: invalid CEN header (bad signature)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.jar.JarFile.<init>(JarFile.java:135)
at java.util.jar.JarFile.<init>(JarFile.java:72)
at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:72)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:48)
at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:70)
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:104)
at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:71)
at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:111)
at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:706)
at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:829)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:334)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:89)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:328)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:308)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:131)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:570)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:891)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1322)
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.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1467)
at org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:332)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:209)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:186)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:561)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:237)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
4/01/2011 5:09:07 PM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Invalid or unreadable WAR file : invalid CEN header (bad signature)
at org.apache.naming.resources.WARDirContext.setDocBase(WARDirContext.java:142)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4657)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4815)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:812)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:787)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:570)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:891)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1322)
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.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1467)
at org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:332)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:209)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:186)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:561)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:237)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
4/01/2011 5:09:07 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error in resourceStart()
4/01/2011 5:09:07 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error getConfigured
4/01/2011 5:09:07 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/Kingdoms] startup failed due to previous errors
also i can now see in the applications list, my app. i click start in the commands for the app but get a message at the top of the screen saying 'FAIL - Application at context path /Kingdoms could not be started'
what am i doing wrong? how to fix this?
the war archive is corrupt or invalid.
check that the war generation procedure is not failing and that the war file is a valid zip file prior to copying to your pen drive etc.
if you're on windows you can do this by changing the file extension to .zip and opening with a zip program such as winzip or winrar.
if you're on another operating system you probably don't need to change the extension.
if the war is a valid zip it's probably being corrupted as a result of your transfer process ie going onto or from your pen drive.
It could be a file protection issue, which you can fix by issuing something like:
chmod 755 webapp.war
it happened to me that my sftp would just slap a 700 on the file transferred, causing that error.
This might be due to one of the following reasons.
Corrupted WAR file
Corrupted JAR files under WEB-INF/lib folder
First thing to check is if you have free space on your disk. If your partition is 100% full, then it will be impossible to extract the .WAR file.
have same error - with war all ok, restarting Tomcat resolve problem
so i think it's becouse Tomcat start deploy war before it fully uploaded
I had the same problem, and rebuilding/uploading the war was NOT fixing the problem. What I ended up doing to fix it was uploading the war under a different name, then renaming the war once it had successfully deployed. A bit bizarre that this would work, but it was a better solution for me than restarting tomcat.
also possibly because of an incorrect entry in solr.xml
It must point to where the .war file is located.
Also look out for file permissions of the .war file you have deployed. For me that was the cause.
In my case it was the manifest file.
Class-Path:
should followed by a whitespace.

Categories