Since upgrading to install4j 7.0.5 and Java 10, users that run our application on Windows more and more often report that the application throws
java.lang.NoSuchMethodError: <init>
at javafx.graphics/com.sun.glass.ui.win.WinApplication.staticScreen_getScreens(Native Method)
at javafx.graphics/com.sun.glass.ui.Screen.initScreens(Unknown Source)
at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
UiLauncher (WAITING)
at java.base#10.0.1/jdk.internal.misc.Unsafe.park(Native Method)
at java.base#10.0.1/java.util.concurrent.locks.LockSupport.park(Unknown Source)
at java.base#10.0.1/java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(Unknown Source)
at java.base#10.0.1/java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(Unknown Source)
at java.base#10.0.1/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(Unknown Source)
at java.base#10.0.1/java.util.concurrent.CountDownLatch.await(Unknown Source)
at platform/javafx.graphics#10.0.1/com.sun.javafx.tk.quantum.QuantumToolkit.startup(Unknown Source)
at platform/javafx.graphics#10.0.1/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
at platform/javafx.graphics#10.0.1/com.sun.javafx.application.PlatformImpl.startup(Unknown Source)
at platform/javafx.swing#10.0.1/javafx.embed.swing.JFXPanel.initFx(Unknown Source)
at platform/javafx.swing#10.0.1/javafx.embed.swing.JFXPanel.<init>(Unknown Source)
at java.base#10.0.1/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base#10.0.1/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base#10.0.1/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base#10.0.1/java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.base#10.0.1/java.lang.Class.newInstance(Unknown Source)
at app//...
when starting the application though the install4j created exe file. The error is triggered by creating an instance of javafx.embed.swing.JFXPanel through reflection:
Class.forName("javafx.embed.swing.JFXPanel").newInstance();
We currently suspect that for some reason an incompatible DLL is loaded (glass.dll seems to contain the native method mentioned in the stacktrace).
Does anyone know how to prevent this error? E.g. is there are way to restrict the java.library.path used when executing the application through the install4j-generated exe to the Java runtime environment that was embedded in the installer and installed locally with the application?
According to one user, the error does not occur if the application is started "manually" using the
java -jar app.jar
command. So it seems the problem lies with the install4j created executable.
The workaround to this problem seems to be to remove all occurences of "glass.dll" from your system %PATH%.
I believe a fix must be implemented somewhere else, though; either in the Java runtime or in the Install4j code, but cannot be implemented in the Java code of the actual app:
For some reason the Java runtime version in Install4j checks the bundled JRE last when locating the libraries. In this case the problematic native library is glass.dll which should contain the requested <init> method but if anywhere in your %PATH% there is an older, incompatible version of glass.dll (e.g. from a previous Java 8 installation) that file will be loaded with a higher precedence and then the application will crash natively.
This is not a problem in the code of the application (the java code), nor a problem with the bundled JDK, this is a problem of how the install-4j-generated exe files (or maybe Java internally) tries to resolve native dlls. Instead of checking all path elements first, it should be checking the bundled JRE directory, first.
With Procmon you can see that it loads arbitrarily placed glass.dll files in the path, first: I added one from JDK 1.8 into one of my path elements and got this (plus the crash):
Related
I have a Java Project (an application to play connect 4) and I want to turn it into an executable file. I created this project in VsCode, and I am using the Java Language Server (see details below). I extracted the .jar file, and used Launch4J to turn it into an executable, and when I run it, I get an error message (see below).
I researched the problem, and it seems that I need to compile my code targeting Java SE 8 rather than 17 (I have 17 currently installed). Could anyone explain to me how I should do this, or is there anything else I'm doing wrong?
The project has multiple files. I'm not sure if this is relevant, but the project has no external dependencies, although it does use javax.swing, javax.sound, and java.awt (as well as java.io.File, java.io.IOException, and java.util.Random, but I'm pretty sure those are irrelevant).
I have eclipse installed if it's necessary, but I only installed it today, and have no experience using it at all. The JDK I am using is (I believe) version 1.8.0_321. (At least this is what I get when I type in java -version.)
The Java compiler version is javac 17.0.2
When I try to run the executable generated by Launch4J, I this is the error I get:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime (class file version 61.65535), this version of the Java Runtime only recognizes class file versions up to 52.0
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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
And the popup error:
Java Virtual Machine Launcher
Error: A JNI error has occurred, please check your installation and try again.
Here are the Settings I used in Launch4J:
Output File: C:\Users\username\OneDrive\Coding\Java Connect 4 v.2\Connect 4.exe
Jar: C:\Users\username\OneDrive\Coding\Java\Java Connect 4 v.2\Java Connect 4 v.2.jar
Don't wrap the jar, launch only: NOT ticked
Wrapper Manifest: none
Change dir: .
Command Line args: none
Process priority: Normal
Both Options NOT ticked
Min JRE version: 1.2.0, Prefer public JRE, but use JDK runtime if newer
Max JRE version: none, First 64-bit, then 32-bit. (This was the default.)
All other settings are default.
Download the latest Java JDK version as .exe file (“x64 Installer”) and install by clicking on the .jar file.
Now the server should start again
#Holger has answered this question. The answer to the problem was to ship a custom JRE image with the application with the help of JLink. That way it can be used regardless of the local version of JRE.
The dynamic link library for GLPK for Java could not be loaded.
Consider using
java -Djava.library.path=
The current value of system property java.library.path is:
\\MILP\lib\glpk-4.55\w64
Exception in thread "main" java.lang.UnsatisfiedLinkError:
\\MILP\lib\glpk-4.55\w64\glpk_4_55_java.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.gnu.glpk.GLPKJNI.<clinit>(GLPKJNI.java:24)
at org.gnu.glpk.GLPK.glp_version(GLPK.java:2259)
at TestMain.main(TestMain.java:7)
I have added the correct JAR file
I have given the correct native path for the library
Still the problem persists,
One doubt I have is that the \MILP\lib\glpk-4.55\w64\glpk_4_55_java.dll file is flawed. I checked it using dependencyWalker there it shows some warnings
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: Modules with different CPU types were found.
Any leads would be appreciated
I also faced same issue. I copied glpk_4_55.dll and glpk_4_55_java.dll to C:\Windows\System32 and Everything works fine for me.
You can add the C:\Program Files\GLPK\glpk-4.55\w64 folder to your PATH environment variable
or
copy the glpk_4_55.dll and glpk_4_55_java.dll to C:\Windows\System32 as suggested by Pradeepb
I've got a program that's packaged as a .jar I need to run for school. In essence the program acts as an interface between a user and a DC motor to control speed, angle, etc.
This program (which required MS C++ to install) runs well on everyone's machines running win7 or 8, but not on my XP_x64 machine. When opened from the start menu, it spawns multiple javaw.exe processes, but no application is created. Run from command line, I find this:
C:\Program Files\Quanser\QICii_USB\bin>java -jar usbQICii.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: C
:\Program Files\Quanser\QICii_USB\bin\lib\usbQICii_jni.dll
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.quanser.raskin.QIC_USB.<clinit>(Unknown Source)
at com.quanser.conduit.pic.PICSource.<init>(Unknown Source)
at com.quanser.raskin.RaskinFrame.<init>(Unknown Source)
at com.quanser.raskin.Raskin.<init>(Unknown Source)
at com.quanser.raskin.Raskin.main(Unknown Source)
I've so far been unable to locate the requested .dll on my system. Two primary questions: is there something obvious I've missed? If I could find the .dll on someone else' machine (so far a no-go) could I grab it and use it on mine (x64 compatibility pending, of course).
Check where usbQICii_jni.dll is located.
My guess is that it is in
"C:\Program Files\Quanser\QICii_USB\lib"
If I'm right, go one directory up, and form
"C:\Program Files\Quanser\QICii_USB"
execute
"java -jar bin\usbQICii.jar"
First off. I am a newbie and green with respect to Java programming.
I created a Java Eclipse "SWT" "Application Window" on a Eclipse Kepler 4.3.1 (32-bit) running WindowBuilder and SWT (swt.jar). The design view is a composite.
The java application runs fine from Eclipse. I simply press the play button and presto.
Problem:
Issuing
java -cp . PkgNetAccelerator32.netAcceleratorApp
yields the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
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: org.eclipse.swt.widgets.Composite
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
I was doing some research and several posts on other issues suggested that the cure is to create a manifest. I saw an article that said something like:
Select the src folder, right click and select export, then Java, then JAR file, specify Manifest.jar and a path on the folder, make sure the "Generate the manifest file" is selected, and press finish.
I created the manifest file and tried launching it with the following command line:
java -jar ../Manifest.jar -cp . PkgNetAccelerator32.netAcceleratorApp
That yielded the same error message above.
I saw another article that said that one should add in the swt.jar file, but that is taken care of by the manifest. No? Specifying "swt.jar" instead of the manifest that I created resulted in an error message:
no main manifest attribute, in ../swt.jar
That error message makes sense.
I am at a loss. How do I run the java application?
I am testing on my Windows 7 Professional 64-bit desktop, but I need to run on CENTOS too. That should be no problem, as I assume whatever the fix on Windows is, will work on CENTOS.
UPDATE:
I placed the two lib files in a /lib folder to match the answer given. I then issued the following command line and got the following error message.
C:\SoftDev\Projects\NetAccelerator\JavaWorkspace\NetAccelerator32>java -cp "bin/*;lib/*" PkgNetAccelerator32.netAcceleratorApp
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at PkgNetAccelerator32.netAcceleratorApp.open(netAcceleratorApp.java:43)
at PkgNetAccelerator32.netAcceleratorApp.main(netAcceleratorApp.java:33)
I found the following article, which produces a command line that works, just that is not reasonable for sending. I much rather use the answer.
Lets assume you have a eclipse project structure similar to this:
Workspace
-> Project
-> src (source code directory)
-> bin (compiled byte code directory as JAR)
-> lib (jar directory)
-> .classpath (eclipse file)
-> .project (eclipse file)
I am assuming that you are exporting the JAR as an executable JAR.
So in order to run a class in that exported JAR with another JAR from the lib directory (swt.jar) while your working directory is the Project directory you will need to execute:
java -cp "bin/*:lib/*" PkgNetAccelerator32.netAcceleratorApp
Using wildcards requires Java 6 or later
Please note: CENTOS requires : as a path separator. Windows uses a semi-colon.
This will add your classes and the swt classes onto the classpath and run your main class PkgNetAccelerator32.netAcceleratorApp
SWT 32bit vs 64bit
You will either need to use a 32bit JVM locally or continue to use a 64bit JVM and use the 64bit version of swt; see swt on windows 64 bit. I would suggest you match your version of your local JVM (32bit or 64bit) with the version that you will be running on the CENTOS machine. You will however need a different swt jar for CENTOS.
I have made a application to grab video from a webcam and detect motion using OpenCV and JavaCV. I am trying to export as an executable jar using eclipse. The program runs fine in eclipse as does the exe jar on the computer I coded the program on.
What I am trying to accomplish is to make the exe Jar run on computers that don't have OpenCV installed. Basically what I would consider a portable application. When I run the exe jar on a different computer that has nothing installed other than the JRE I get unsatisfied link errors seen below.
Exception in thread "Video Thread" java.lang.UnsatisfiedLinkError: C:\Users\JohnD\AppData\Local\Temp\javacpp91062429652918\jniopencv_core.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:566)
at com.googlecode.javacpp.Loader.load(Loader.java:489)
at com.googlecode.javacpp.Loader.load(Loader.java:431)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:453)
at com.googlecode.javacv.cpp.opencv_imgproc.<clinit>(opencv_imgproc.java:97)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:453)
at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:85)
at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:174)
at VideoPanel.run(VideoPanel.java:163)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_core244 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:481)
... 13 more
I have looked for a solution to what I am doing wrong. Most of the topics I have come across with unsatisfied link errors like the ones I am receiving have been trying to get it to run the first time through within there IDE, which is not the case here. I would think my dependencies are correct in the libraries in the build path since I can get it to run perfectly when I am on the computer that has everything installed but I still believe I am doing something wrong with the build.
Again I am trying to make it so the Jar can run on computers where OpenCV/JavaCV is not installed. Any help would be greatly appreciated.
If opencv is not installed in the target machine, than you need to deliver the necessary opencv's dll file and set the corresponding library path, opencv is a precondition of javacv
for example:
jar yourapp.jar -Djava.library.path="/path/to/OpenCV/library"
also check this answer