Question

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.

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. And if I try (later to run in NetBeans) to launch application from dist folder everything work perfectly. 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??

Was it helpful?

Solution

What the problem is

The javafx-ui-sandbox project you link to is obsolete and incompatible with later JavaFX versions under some circumstances.

How to fix it

I advise using ControlsFX instead. 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. 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.

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:

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). So you are signing your jars with a different certificate than Oracle used to sign the JavaFX jars. The JavaFX jars include the bulk of the code in the javafx.scene.control package. 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.

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.

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 (e.g. 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. But again, you are probably better off using the ControlsFX library instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top