简体   繁体   中英

Hibernate NoClassDefFoundError org.hibernate.cfg.Configuration in Java web application

I' m developing a simple JSF application which uses Hibernate. I imported all required libraries to WEB-INF/lib folder and also point them in classpath. But when I tried to compile it I got error:

在此处输入图片说明

Here is code where I create SessionFactory and use it:

private static SessionFactory buildSessionFactory()
{
  try
  {
  Configuration configuration = new Configuration();//This line
    configuration.configure();
    serviceRegistry = new   ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(   );        
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    return sessionFactory;
         }
       catch (Exception e)
{
throw new ExceptionInInitializerError(e);
  }
  }
 public static SessionFactory getSessionFactory()
 {
return buildSessionFactory();
 }

And here I use it:

 public static void  saveUser( String title)
     {
         Session session = HibernateUtil.getSessionFactory().openSession();  
         Client client = new Client();
         ......

So what am I doing wrong? How can I fix this?

The javax.transaction.SystemException is in the jta-xyjar (xy is the required version for the version of Hibernate you use). It should be in your classpath.

Hibernate requires a lot of libraries. To manage the dependencies, you should use something like Maven or Ivy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM