0

我有一个使用 Hibernate 进行数据库操作的 JavaFX 项目。我已经使用 Maven 成功构建了应用程序,并使用 .exe 创建了一个 .exe 文件jpackage。每当我运行 exe 文件时,Caused by: java.lang.NoClassDefFoundError: javax/naming/NameNotFoundException从 Hibernate 获取。但是当我使用 JAR 文件运行应用程序时,它可以正常工作。任何帮助将不胜感激。请在下面找到我的休眠配置。

    public static SessionFactory getSessionFactory() throws DbConnectException{
        try {
            if (sessionFactory == null) {
                properties = new DbProperties().loadFromPropertyFile();
                config = new Configuration();
                config.configure("hibernate.cfg.xml").addProperties(properties);
                ServiceRegistry registry = new StandardServiceRegistryBuilder().
                        applySettings(properties).build();
                sessionFactory = config.buildSessionFactory(registry);
            }
        } catch (HibernateException e) {
            logger.error("Error In Establishing DB connection, {}", e);
            throw new DbConnectException("Error while connecting to Database::"+ e.getMessage(), e.getCause());
        }
        return sessionFactory;
    }

运行 .exe 文件时抛出错误

Caused by: java.lang.NoClassDefFoundError: javax/naming/NameNotFoundException
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Unknown Source)
        at org.jboss.logging.Logger.doGetMessageLogger(Logger.java:2562)
        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2530)
        at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
        at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28)
        at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24)
        at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:87)
        at com.arjun.learning.db.HibernateConfig.getSessionFactory(HibernateConfig.java:38)
        at com.arjun.learning.PrimaryController.switchToSecondary(PrimaryController.java:12)
        ... 58 more
Caused by: java.lang.ClassNotFoundException: javax.naming.NameNotFoundException
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 68 more

使用的环境 Java:版本 - 15 休眠:版本 5.5.3.Final

4

0 回答 0