简体   繁体   English

将带有数据库的应用程序导出到Netbeans中的可执行Jar

[英]Exporting Applications with Databases to Executable Jar in Netbeans

I'm building a desktop application with an Apache Derby database. 我正在使用Apache Derby数据库构建桌面应用程序。 When I run the application from Netbeans, it works fine, but when I run the application's executable jar file, I get a "java.lang.ExceptionInInitializerError" "Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager." 当我从Netbeans运行该应用程序时,它运行良好,但是当我运行该应用程序的可执行jar文件时,出现“ java.lang.ExceptionInInitializerError”错误,原因是:java.lang.IllegalStateException:试图在封闭状态下执行操作EntityManager。”

The jar file was created by right-clicking the project in Netbeans, and clicking "Clean and Build". 右键单击Netbeans中的项目,然后单击“清理并构建”,即可创建jar文件。

I've looked at the the following resources, but the information wasn't applicable: 我查看了以下资源,但该信息不适用:

This is my first time using Derby, so it's probably something simple that I'm missing. 这是我第一次使用Derby,因此可能缺少一些简单的东西。

Stack trace: 堆栈跟踪:

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

As it turns out, I made a (very) silly mistake in my code. 事实证明,我在代码中犯了一个(非常)愚蠢的错误。 I closed the EntityManager that I made the query on in the line before I called getSingleResult() on my query. 在对查询调用getSingleResult()之前,我关闭了在其上进行查询的EntityManager。 I'm not quite sure why the program worked when I ran it from Netbeans, but the problem is solved now. 当我从Netbeans中运行该程序时,我不太确定为什么该程序可以运行,但是现在问题已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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