gpt4 book ai didi

javafx 在 Netbeans IDE 之外运行应用程序

转载 作者:搜寻专家 更新时间:2023-11-01 03:39:20 25 4
gpt4 key购买 nike

我在通过“dist 文件夹”中的 .jar 运行 javaFX 应用程序时遇到问题,后来我通过 NetBeans 清理并构建了项目。

C:\NetBeansProjects\Gestore\dist>java -jar
Gestore.jar
log4j:ERROR Could not read configuration file [conf\log4j.properties].
java.io.FileNotFoundException: conf\log4j.properties (Impossibile trovare il per
corso specificato)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurato
r.java:372)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.
java:403)
at gestore.Gestore.<init>(Gestore.java:97)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
pl.java:276)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:
47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Unknown Source)
log4j:ERROR Ignoring configuration file [conf\log4j.properties].
log4j:WARN No appenders could be found for logger (gestore.Utility).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more in
fo.
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.javafx.main.Main.launchApp(Main.java:642)
at com.javafx.main.Main.main(Main.java:805)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
pl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:
47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.SecurityException: class "javafx.scene.control.Dialogs"'s s
igner information does not match signer information of other classes in the same
package
at java.lang.ClassLoader.checkCerts(Unknown Source)
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at gestore.Gestore.loadEserciziFromDB(Gestore.java:407)
at gestore.Gestore.start(Gestore.java:178)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179
)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176
)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29
)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more

但如果我从 netBeans 运行项目,一切都会完美无缺。如果我尝试(稍后在 NetBeans 中运行)从 dist 文件夹启动应用程序,一切都会完美运行。事实上

C:\NetBeansProjects\Gestore\dist>java -jar
Gestore.jar
log4j:ERROR Could not read configuration file [conf\log4j.properties].
java.io.FileNotFoundException: conf\log4j.properties (Impossibile trovare il per
corso specificato)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurato
r.java:372)
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.
java:403)
at gestore.Gestore.<init>(Gestore.java:97)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherIm
pl.java:276)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:
47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Unknown Source)
log4j:ERROR Ignoring configuration file [conf\log4j.properties].
log4j:WARN No appenders could be found for logger (gestore.Utility).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more in
fo.

所以我认为这个问题是由 Java.Lang.SecurityException 引起的(是的,我知道 log4j 属性有问题),也许在这里 https://github.com/marcojakob/javafx-ui-sandbox/issues/5有一个解决方案,但为什么呢?

最佳答案

问题是什么

javafx-ui-sandbox在某些情况下,您链接到的项目已过时且与更高版本的 JavaFX 不兼容。

如何修复

我建议使用 ControlsFX反而。 ControlsFX 具有 javafx-ui-sandbox(以及更多)的所有功能,并且在构建时不会与 JavaFX 系统类发生冲突。它也是一个更加积极维护和开发的项目。

如果您不能使用最新版本的 ControlsFX 所需的最低 Java 8 版本,曾经有一个 ControlsFX 2.x backport , 但它不再有任何相关内容。

随后是冗长且不必要的解释

javafx-ui-sandbox 是一个原型(prototype)系统,它包含的类与某些 Java 发行版中包含的类冲突 - 这就是为什么您会得到:

Caused by: java.lang.SecurityException: class "javafx.scene.control.Dialogs"'s 
signer information does not match signer information of other classes
in the same package.

这里发生的是,您在 jar 中包含了一个 javafx-ui-sandbox 类 ( javafx.scene.control.Dialogs ) 并对其进行了签名(可能您使用的是 NetBeans 和 have the checkbox to self-sign jars switched on ,但还有其他方法可以签名)。因此,您使用的证书与 Oracle 用于签署 JavaFX jar 的证书不同。 JavaFX jar 包含 javafx.scene.control 包中的大部分代码。作为 Java 一些晦涩规则的一部分,您不能使用两个不同的证书在同一个包中签署代码,否则会生成安全异常。

当您在 NetBeans 中执行时,您可能看不到问题,因为您没有签署您的应用程序以在开发环境中执行它,但是当您构建正在执行的 jar 文件时,您也在签署 jar文件,此时 jar 将无法工作。

简单的解决方法就是将 javafx-ui-sandbox 源代码复制到您的项目中,并将包名称从 javafx.scene.control 更改为其他名称(例如 com.yourcompany.control)。这样,类包就不会与为 JavaFX 系统提供的默认包发生冲突,并且您可以签署代码(包括 com.yourcompany.control.Dialogs 类)而不会引起任何问题。但同样,您最好还是使用 ControlsFX 库。

关于javafx 在 Netbeans IDE 之外运行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19092621/

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