4

稍后我通过“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一个解决方案,但为什么?

4

1 回答 1

1

问题是什么

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

如何修复它

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

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

冗长而不必要的解释如下

javafx-ui-sandbox 是一个原型系统,其中包含与某些 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 并打开了用于自签名 jar 的复选框,但您还可以通过其他方式签名)。因此,您使用的证书与 Oracle 用于签署 JavaFX jar 的证书不同。JavaFX jar 包含 javafx.scene.control 包中的大部分代码。作为 Java 一些晦涩规则的一部分,您不能使用两个不同的证书对同一个包中的代码进行签名,否则会产生安全异常。

在 NetBeans 中执行时,您可能看不到问题,因为您没有签署应用程序以在开发环境中执行它,但是当您构建正在执行的 jar 文件时,您也在签署 jar 文件,位于哪一点罐子不起作用。

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

于 2013-10-01T07:20:05.283 回答