问题
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.
回答1:
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
回答2:
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.
回答3:
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
来源:https://stackoverflow.com/questions/52906570/javafx-11-using-maven-throws-exception-windowsnativerunloopthread