Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX 11 using Maven throws Exception: "WindowsNativeRunloopThread"

I have been testing JavaFX 11 using Maven and cannot get it to work. I have Open JDK 11 installed and if adding jars to build path from downloadable .zip everything works just fine.

However when I use the recommended POM file from the javafx 11 site I get the following error.

Exception in thread "WindowsNativeRunloopThread" 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(Screen.java:412)
    at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Application.java:152)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at javafx.graphics/com.sun.prism.d3d.D3DPipeline.getAdapterOrdinal(D3DPipeline.java:205)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.assignScreensAdapters(QuantumToolkit.java:695)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runToolkit(QuantumToolkit.java:313)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$startup$10(QuantumToolkit.java:258)
    at javafx.graphics/com.sun.glass.ui.Application.lambda$run$1(Application.java:153)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)

This problem seems to have cropped up once here but none of the solutions in that thread have worked.

Does anyone have suggestions on how to go about diagnosing the problem? I am running in Eclipse 4.9 and have attached a screenshot of two projects which are identical other than one uses maven and the other has jars added to the build path. Any help much appreciated. Two projects. javafx11mvn is a Maven project loading javafx11 dependencies from the POM file, java11test2 is a standard java project with javafx11 jars dded to build path]

like image 734
macster110 Avatar asked Oct 20 '18 14:10

macster110


4 Answers

The solution to this problem is in comments (kleopatra). For quick reference you need to add

-Djava.library.path=C:/anywhere-outside-eclipse 

(I tested using -Djava.library.path=C:/) to the VM arguments. This means javafx 11 works with Maven inside eclipse.

like image 144
macster110 Avatar answered Nov 13 '22 06:11

macster110


This is not Eclipse only problem. I have exactly the same issue when running OpenJFX app in Intellij IDEA 2018.3.2. If any other Java version specified in Windows %Path% env variable then forementioned exception will be thrown.

For instance I use Java 8 as default SDK and playing with Java 11. It's not working that way. It work only if I'll delete Java 8 bin directory from %Path%.

This is rather confusing (and I believe it's a bug) because I don't see any relations to Java 8 when I launch my project in IDE:

C:\Software\Java\openjdk-11\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Project\helloworld -Dmaven.home=C:\Software\Maven\3.6.0 -Dclassworlds.conf=C:\Software\Maven\3.6.0\bin\m2.conf "-javaagent:C:\Software\IntelliJ IDEA\CE_2018.3.2\lib\idea_rt.jar=64808:C:\Software\IntelliJ IDEA\CE_2018.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Software\Maven\3.6.0\boot\plexus-classworlds-2.5.2.jar org.codehaus.classworlds.Launcher -Didea.version=2018.3.2 -T 2 -DskipTests=true exec:java
like image 38
enzo Avatar answered Nov 13 '22 07:11

enzo


As suggested in the post linked to by @kleopatra, the problem is that javafx11 is loading the wrong glass.dll file.

While the workaround suggested in other answers works, the OpenJFX tutorial suggests, when possible, to instruct eclipse to use the Java 11 VM to run, so that the correct dll is loaded.

You can modify your eclipse.ini file and (supposing your jdk11 is installed in C:\Program Files\Java\jdk-11.0.2) add the following lines:

-vm
C:\Progra~1\Java\jdk-11.0.2\bin\javaw.exe
like image 4
Federico klez Culloca Avatar answered Nov 13 '22 07:11

Federico klez Culloca


Adding the following lines in the pom.xml file have resolved this issue for me.

In the POM file for the ArtifactID -- javafx-maven-plugin add the following lines in the configuration tag section.

    <options> <option>-Djava.library.path=C:\tmp</option> </options>
    <executable>C:\openjdk11\jdk-11\bin\java.exe</executable>

Create the tmp folder in advance before you make the change to pom.xml file. Also ensure that java11 is present in the path mentioned above. otherwise mention the path according to the java11 path in your system.

like image 1
Ajaya Krishna Avatar answered Nov 13 '22 08:11

Ajaya Krishna