maven Java PersistenceException(如果作为jar执行)

bf1o4zei  于 2023-06-05  发布在  Maven
关注(0)|答案(1)|浏览(198)

我目前正在使用JDA构建一个Discord Bot,并尝试使用Hibernate添加数据库连接。如果我在IntelliJ中执行程序,它可以正常工作,没有任何错误。但是在我编译了Project并执行jar文件之后,我得到了这个错误:(我的目标是在docker容器中执行bot。

Exception in thread "main" javax.persistence.PersistenceException: Unable to build entity manager factory
        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
        at ch.ydavid.pizzabot.DAO.GuildConfigDAO.<init>(GuildConfigDAO.java:12)
        at ch.ydavid.pizzabot.manager.DynamicVoiceManager.<init>(DynamicVoiceManager.java:18)
        at ch.ydavid.pizzabot.manager.GeneralManager.<init>(GeneralManager.java:5)
        at ch.ydavid.pizzabot.Main.main(Main.java:32)
Caused by: org.hibernate.jpa.boot.archive.spi.ArchiveException: Could not build ClassFile
        at org.hibernate.jpa.boot.scan.spi.ClassFileArchiveEntryHandler.toClassFile(ClassFileArchiveEntryHandler.java:88)
        at org.hibernate.jpa.boot.scan.spi.ClassFileArchiveEntryHandler.handleEntry(ClassFileArchiveEntryHandler.java:65)
        at org.hibernate.jpa.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:176)
        at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:72)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.scan(EntityManagerFactoryBuilderImpl.java:723)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:219)
        at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:51)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:182)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:131)
        at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:88)
        at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:69)
        ... 6 more

我已经检查了jar文件中的javax.persistence依赖项和persistence.xml文件。两人都在院子里。
我的源代码在GitHub上。(add_jpa分支)

l7wslrjt

l7wslrjt1#

尝试重现藏物

File > Project Structure > Artifacts

然后删除当前的并创建一个新的

+ > Jar > From Modules With Dependencies

添加你的主类,然后点击OK和Apply。然后继续建造藏物

File > Build > Build Artifacts > Build

如果它不这样工作,请添加评论/回答这篇文章

相关问题