views:

87

answers:

2

Hi, I deployed my application to the official server and started getting this error:

Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class app.HibernateUtil org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.ajax.search_jsp._jspService(search_jsp.java:67) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.lang.NoClassDefFoundError: Could not initialize class app.HibernateUtil app.PersistanceHelper.(PersistanceHelper.java:23) app.SearchBean.(SearchBean.java:26) org.apache.jsp.ajax.search_jsp._jspService(search_jsp.java:54) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Before the deployment the app worked fine. My HibernateUtil class was generated by Netbeans wizard. I cannot see where does the problem originate. I spent some time searching for the similar problem in google but the answers found (missing jars, spelling errors, etc) are not applicable in this solution as it works on my PC, just not on the official server. Any thoughts on that? I can add the rest of the sources if needed. Apache Tomcat log does not contain any errors. Thanks for any help.

+1  A: 

I think that your class is on the classpath but the ClassLoader runs into an error when trying to load the class (as hinted by the message). This typically happens when the class has a static block or static members which use a Class that can't found by the ClassLoader.

In the particular case of this generated HibernateUtil.java, it should have something like this:

static {
  URL myurl = Thread.currentThread().getContextClassLoader().getResource("/some/path/to/hibernate.cfg.xml");
  sessionFactory = new Configuration().configure(myurl).buildSessionFactory();
}

So:

  • Make sure the hibernate configuration file is present were expected.
  • Make sure the Hibernate jars are present on the class path of the target machine.
  • Maybe add a try { ... } catch (Throwable t) { ... } in your static block to log the error.
Pascal Thivent
+1  A: 

You should read the user documentation that comes with the Hibernate distribution. The Hibernate JARs have a bunch of runtime dependencies on other JARs, such as some of the Apache Commons ones, and the "slf4j" JARs for example. If those are missing at runtime Hibernate will not function even if all the Hibernate JARs are in the right place.

Jim Tough