I have modified my Java project(Web service) into Dynamic web module. I'm using Tomcat 7.0.59 as server. While starting server it is getting started without any issues. But once if I tried to access the Web service method then I will end up with the error saying that -"Could not initialize class DataLayer.HibernateAdapter java.lang.NoClassDefFoundError: Could not initialize class DataLayer.HibernateAdapter". Anyone please help me than just marking it a "Duplicate". If code has to be modified, please provide me detail steps. Thanks!!
Console Log:
Mar 10, 2015 2:09:07 PM com.sun.xml.ws.server.sei.EndpointMethodHandler invoke
SEVERE: Could not initialize class DataLayer.HibernateAdapter
java.lang.NoClassDefFoundError: Could not initialize class DataLayer.HibernateAdapter
at DataLayer.DatabaseContext.<init>(DatabaseContext.java:12)
at DataLayer.ConsumerDetails.getConsumerdetails(ConsumerDetail.java:84)
at ManageLayer.Authenticate(AuthenticationManager.java:50)
at ManageLayer.Console.GetProductsList(Console.java:484)
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 com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
DatabaseContext.java :
public class DatabaseContext
{
private final Session session;
public DatabaseContext() {
this.session = HibernateAdapter.getSessionFactory().openSession();
}
public Session delegate() {
return session;
}
public void close() {
session.flush();
session.close();
}
}
class HibernateAdapter
{
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try
{
return new AnnotationConfiguration()
.addAnnotatedClass(Consumer.class)
.addAnnotatedClass(Product.class)
.addAnnotatedClass(PriceTag.class)
.addAnnotatedClass(Barcode.class)
.configure().buildSessionFactory();
}
catch (Throwable e)
{
System.err.println("Exception while creating Initial SessionFactory" + e);
throw new ExceptionInInitializerError(e);
}
}
public static SessionFactory getSessionFactory()
{
return sessionFactory;
}
public static void shutdown() {
getSessionFactory().close();
}
}