简体   繁体   English

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

[英]javafx running application outside Netbeans IDE

I'm having trouble running a javaFX application through the .jar in the "dist folder" later that I have clean and build project by NetBeans. 我通过“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

But if I run project from netBeans everything works perfectly. 但是,如果我从netBeans运行项目,一切都很完美。 And if I try (later to run in NetBeans) to launch application from dist folder everything work perfectly. 如果我尝试(稍后在NetBeans中运行)从dist文件夹启动应用程序,一切都很完美。 In fact 事实上

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.

So I think that problem is caused by Java.Lang.SecurityException (yes I know there is a problem with log4j properties), and maybe here https://github.com/marcojakob/javafx-ui-sandbox/issues/5 there is a solution, but why?? 所以我认为这个问题是由Java.Lang.SecurityException引起的(是的,我知道log4j属性存在问题),也许在这里https://github.com/marcojakob/javafx-ui-sandbox/issues/5一个解决方案,但为什么??

What the problem is 问题是什么

The javafx-ui-sandbox project you link to is obsolete and incompatible with later JavaFX versions under some circumstances. 您链接到的javafx-ui-sandbox项目已过时,并且在某些情况下与后续JavaFX版本不兼容。

How to fix it 如何解决它

I advise using ControlsFX instead. 我建议使用ControlsFX ControlsFX has all of the functions of the javafx-ui-sandbox (and more) and is built so that it does not clash with JavaFX system classes. ControlsFX具有javafx-ui-sandbox(以及更多)的所有功能,并且构建为不与JavaFX系统类冲突。 It is also a much more actively maintained and developed project. 它也是一个更积极维护和开发的项目。

If you cannot use the minimum Java 8 version required for the latest version of ControlsFX, there used to be a ControlsFX 2.x backport , but it no longer has any relevant content. 如果您不能使用最新版本的ControlsFX所需的最低Java 8版本,那么曾经有一个ControlsFX 2.x backport ,但它不再具有任何相关内容。

Long and unnecessary explanation follows 下面是长期不必要的解释

javafx-ui-sandbox was a prototyping system that includes classes which clash with classes included in some Java distributions - which is why you get: 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.  

What is happening here is that you are including a javafx-ui-sandbox class ( javafx.scene.control.Dialogs ) in your a jar and signing it (probably you are using NetBeans and have the checkbox to self-sign jars switched on , but there are other ways you could be signing). 这里发生的事情是你在一个jar中包含一个javafx-ui-sandbox类( javafx.scene.control.Dialogs )并对其进行签名(可能你正在使用NetBeans并打开自签名jar的复选框 ,但是还有其他方法可以签名)。 So you are signing your jars with a different certificate than Oracle used to sign the JavaFX jars. 因此,您使用与Oracle用于签署JavaFX jar的证书不同的证书来签署您的罐子。 The JavaFX jars include the bulk of the code in the javafx.scene.control package. JavaFX jar包含javafx.scene.control包中的大部分代码。 As part of some obscure rule of Java, you can't sign code in the same package with two different certificates or it will generate a security exception. 作为Java的一些模糊规则的一部分,您不能使用两个不同的证书在同一个包中签名代码,否则它将生成安全性异常。

Likely you don't see the issue when you are executing within NetBeans because you aren't signing your application to execute it within the development environment, but when you build the jar file you are executing, you are also signing the jar file, at which point the jar won't work. 您在NetBeans中执行时可能没有看到问题,因为您没有在开发环境中对应用程序进行签名以执行它,但是当您构建正在执行的jar文件时,您还要签署jar文件,哪个罐子不起作用。

The easy fix for you is just to copy the javafx-ui-sandbox source into your project and change the package name from javafx.scene.control to something else (eg com.yourcompany.control). 您可以轻松修复javafx-ui-sandbox源代码并将包名称从javafx.scene.control更改为其他内容(例如com.yourcompany.control)。 That way the class packages won't clash with the default packages provided for the JavaFX system and you can sign your code (including the com.yourcompany.control.Dialogs class) without causing any issues. 这样,类包不会与为JavaFX系统提供的默认包冲突,您可以在不引起任何问题的情况下签署代码(包括com.yourcompany.control.Dialogs类)。 But again, you are probably better off using the ControlsFX library instead. 但同样,您可能最好使用ControlsFX库。

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

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