gpt4 book ai didi

java - Java Web 应用程序中的 Hibernate NoClassDefFoundError org.hibernate.cfg.Configuration

转载 作者:行者123 更新时间:2023-12-01 14:29:06 25 4
gpt4 key购买 nike

我正在开发一个使用 Hibernate 的简单 JSF 应用程序。我将所有必需的库导入到 WEB-INF/lib 文件夹中,并将它们指向类路径。但是当我尝试编译它时出现错误:

enter image description here

这是我创建 SessionFactory 并使用它的代码:

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();
}

我在这里使用它:

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

那我做错了什么?我该如何解决这个问题?

最佳答案

javax.transaction.SystemException 位于 jta-x.y.jar 中(x.y 是您使用的 Hibernate 版本所需的版本)。它应该在您的类路径中。

Hibernate 需要很多库。要管理依赖关系,您应该使用 Maven 或 Ivy 之类的东西。

关于java - Java Web 应用程序中的 Hibernate NoClassDefFoundError org.hibernate.cfg.Configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16958154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com