javafx running application outside Netbeans IDE - java

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??

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.

Related

JMeter: NoClassDefFoundError error when used jackson jar

I'm creating a custom Java sampler in JMeter. It's working just fine. However, when I wanted it to return a result in JSON, JMeter didn't found the .jar for the jackson-databind library, which is needed for the creation of the JSON.
I put it to the /lib/ext folder in the JMeter main directory. I also copied to /lib, to no avail. (I know that /lib/ext shouldn't be used for dependency jars, but JMeter doesn't find my utility jars in /lib in my experience.)
I tried adding the path to the variables search_paths, user.classpath and plugin_dependency_paths in jmeter.properties. I tried with absolute path, relative path, with slash, with backslash, but neither helped.
I tried setting the JMETER_HOME variable to the address of my installation. It worked, yet it didn't help.
I tried running in two environments. The first is within Eclipse (I copied JMeter to a workspace folder, then imported the project), with JMeter 4.0. I got this error in the log:
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper
at (creating ObjectMapper here)
at (creating ResponseJSON here)
at org.apache.jmeter.protocol.java.sampler.JavaSampler.sample(JavaSampler.java:197) ~[ApacheJMeter_java.jar:4.0 r1823414]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:490) ~[ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:416) ~[ApacheJMeter_core.jar:4.0 r1823414]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:250) ~[ApacheJMeter_core.jar:4.0 r1823414]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
I also ran JMeter 3.3 from the .bat file, adding the jars to the same place. I got this error on the console:
Unknown error checking for existence of class: com.fasterxml.jackson.databind.ObjectMapper
java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/Versioned
at java.lang.ClassLoader.defineClass1(Native Method)
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 java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:141)
at org.apache.logging.log4j.util.LoaderUtil.isClassAvailable(LoaderUtil.java:115)
at org.apache.logging.log4j.core.util.Loader.isClassAvailable(Loader.java:310)
at org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory.<init>(YamlConfigurationFactory.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:188)
at org.apache.logging.log4j.core.config.ConfigurationFactory.addFactory(ConfigurationFactory.java:190)
at org.apache.logging.log4j.core.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:164)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:613)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:122)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:43)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:358)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at org.apache.jmeter.JMeter.<clinit>(JMeter.java:109)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.apache.jmeter.NewDriver.main(NewDriver.java:246)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.Versioned
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 43 more
I didn't try to debug the classloader, but probably that'll be the next step when I finished posting it here.
I have this version of the file, same as in my POM:
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.9.4
Part of jackson-databind dependencies is specifically jackson-core jar you are probably missing and include missing class in your error: com.fasterxml.jackson.core.Versioned
See Jackson Installation:
The three JAR files (projects) in the Jackson JSON API are:
Jackson Core
Jackson Annotations
Jackson Databind

Modify org.eclipse.jdt.core.dom.ASTPArser

I need to modify org.eclipse.jdt.core.dom.ASTParser class which is in jdt.core jar file. So I created a java project and I created the same package (org.eclipse.jdt.core.dom). but when I want to create a new instance of this class I get this error:
Exception in thread "main" java.lang.SecurityException: class
"org.eclipse.jdt.core.dom.ASTParser2"'s signer 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
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
typeResolution.TypeResolution.main(TypeResolution.java:80)
When I run my code in a plugin mode project I don't have problem, but in a java stand alone project I am getting this error.
Can anyone give me insight into this problem? Thanks.
The original artifact org.eclipse.jdt.core_xyz.jar is signed. When you try to use that jar in combination with your own modified class the JVM will detect that the integrity of the signed jar is broken.
You have two options:
instead of replacing just one file, replace the entire jar with your
own version
re-package the original jar without signing
Depending on your configuration there may be more ripples, because other plug-ins like org.eclipse.jdt.compiler.tool contribute classes to packages that also exist in org.eclipse.jdt.core ("split packages"), which is OK only if both jars are signed by with the same certificate - or not signed at all.

Executing jar file throws class not found error

Using Eclipse, I am modifying a Java project we have been using for years. a specific class method is typically executed by sending a message through IBM WebSphere MQ. However, I now have a need to develop some new functionality and I need to be able to test it out side the MQ world.
I am able to successfully debug the application in Eclipse, but if I attempt to execute the jar file from a command prompt I receive the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: XMLBuilder/Node
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: XMLBuilder.Node
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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more
My build is done using an ant script. This does not include a Class-Path attribute when creating the manifest.
The XMLBuilder.jar file is included in the target jar. Running jar -tf file.jar shows
META-INF/)
META-INF/MANIFEST.MF)
... Omitted for Brevity ...
XMLBuilder.jar
What might I be missing?
Thank you

How to deploy Swing application with JWS in NetBeans?

Is there proper guideline on how to deploy Swing application with JWS?
Here is what I have been trying
Created Swing application with Netbeans. And trying to deploy ready application with Java web start.
Project Property -> Application -> Web start, Enabled Web start, fixed all necessary fields.
By using Tomcat or WAMP server, I was able to run jnlp file, it downloads necessary libraries and right after launch I get following error:
java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException
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 com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 7 more
But json.simple jar file is in classpath and application is running normal locally (without JWS).
Why despite having library in classpath, I get NoClassDefFoundError error?
jnlp file seem to have it listed <jar href="lib/json-simple-1.1.1.jar"/>.
Surfed around net but couldn't find a fix for the issue. Anyone had similar issues, please help! And Please ask for clarification before marking this question as duplicate, thanks!

EJB exception while try to run the client

javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interf
aces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: o
rg.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at Client_TestPortal.main(Client_TestPortal.java:54)
Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFac
tory
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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)
... 5 more
That exception says that initializing of the InitialContext has failed for your Client_TestPortal application. The resaon is that it has been unable to load the class org.jnp.interfaces.NamingContextFactory which (I presume) the default Java Naming provider for your platform.
It appears that your apps classpath is missing a required JAR file. According to this findjar query it could be one of the following:
[LOCAL] jbossall-client.jar
[LOCAL] jbossjmx-ant.jar
[MAVEN2] jnpserver-3.2.3.jar
[MAVEN2] jbossall-client-3.2.1.jar
[MAVEN2] jbossall-client-3.2.3.jar
[MAVEN2] jbossjmx-ant-3.2.3.jar
[MAVEN2] jnp-client-3.2.1.jar
[MAVEN2] jnp-client-4.0.2.jar
... or something like that. Which (if any) of the above JARs is most appropriate is hard to say.
You have not provided enough information like the environment you are using, The app server etc.
Any way it lloks like JNDI related JAR is not on the classpath. If it is in place and still not working, then you may have missed to put the correct context information, so pass the JNDI information to the constuctor of InitialContext.
I had the same problem but I found how to fix it. All you have to do is add the jbossall-client.jar library to the clients project, and done!!! You can find the file inside the client folder.
e.g jboss-6.1.0.Final_GPT\client
I was using Jboss 6.1.0
You can also get help from this link
https://community.oracle.com/thread/1157701?start=0
Hope it helps.

Categories