【问题标题】:Exporting Applications with Databases to Executable Jar in Netbeans将带有数据库的应用程序导出到 Netbeans 中的可执行 Jar
【发布时间】:2017-12-19 21:34:50
【问题描述】:

我正在使用 Apache Derby 数据库构建桌面应用程序。当我从 Netbeans 运行应用程序时,它工作正常,但是当我运行应用程序的可执行 jar 文件时,我得到一个“java.lang.ExceptionInInitializerError”“Caused by: java.lang.IllegalStateException: Attempting to perform an operation on a closed实体管理器。”

jar 文件是通过右键单击 Netbeans 中的项目,然后单击“清理并构建”来创建的。

我查看了以下资源,但信息不适用:

这是我第一次使用 Derby,所以我可能缺少一些简单的东西。

堆栈跟踪:

java.lang.ExceptionInInitializerError
    at myProject.Main.start(Main.java:70)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpenWithSetRollbackOnly(EntityManagerImpl.java:1923)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:508)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
    at graphics.view.Read.<clinit>(Read.java:50)
    ... 10 more

【问题讨论】:

  • 这里发生了什么:Main.java:70
  • 它为程序创建主 gui 对象。在此过程中,它会多次调用数据库。

标签: java netbeans eclipselink


【解决方案1】:

事实证明,我在代码中犯了一个(非常)愚蠢的错误。在我对我的查询调用 getSingleResult() 之前,我关闭了我在该行中进行查询的 EntityManager。当我从 Netbeans 运行该程序时,我不太确定为什么该程序有效,但现在问题已解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-12
    • 2011-12-25
    • 2015-07-31
    • 2012-07-11
    • 2017-05-27
    • 2012-03-25
    • 2011-11-15
    • 1970-01-01
    相关资源
    最近更新 更多