10

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]

Jamie Macaulay
  • 794
  • 6
  • 20
  • what if you use the same runtime for both projects? the first project uses a runtime named _JavaSE-11_, the second _jdk-11.0.1_. I'd suggest to use the working one (second) for the first project as well – P.J.Meisch Oct 20 '18 at 15:06
  • Thanks but they're actually the same runtime, just had two different names for it (changed it anyway and still did not work) – Jamie Macaulay Oct 20 '18 at 15:48
  • You say you have a Maven project, but the project structure doesn't reflect that (i.e. you don't have `/src/main/java` for your source). And you also add a `module-info` class, that you probably don't need? – José Pereda Oct 20 '18 at 17:11
  • Yes, true. That's sloppy. I've created the proper project structure and updated the picture. I've also removed some of the redundant jar files from javafx11test so that the two projects should be exactly the same. I cannot run the project in eclipse without the module-info class. – Jamie Macaulay Oct 21 '18 at 08:59
  • 2
    looks similar to http://mail.openjdk.java.net/pipermail/openjfx-dev/2018-October/022713.html – kleopatra Oct 21 '18 at 09:31
  • Thanks. I had not come across that but yes that is the solution! – Jamie Macaulay Oct 21 '18 at 09:49
  • Some more information: https://github.com/karakun/OpenWebStart/issues/125 – Hendrik Ebbers Jun 05 '20 at 07:35

5 Answers5

14

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.

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Jamie Macaulay
  • 794
  • 6
  • 20
  • 1
    This is a proper solution, as long as this issue is not fixed in Eclipse. Note that this is happening on JavaFX 11 projects with Maven only on Windows when Eclipse VM is set to Oracle JDK 1.8. – José Pereda Nov 04 '18 at 14:03
6

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
enzo
  • 786
  • 1
  • 8
  • 18
4

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
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
1

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.

0

Context: NetBeans IDE 8 and 11 on Windows 10

I had the same problem, but my context was slightly different from the above. I do a lot of work switching between various versions of Java: supporting legacy applications in Java 8 and developing new applications in Java 11.

As it turned out, I had the Java 8 entry in the PATH while trying to develop and run a Java 11 application. The builds completed successfully but at runtime it was exceptions galore. All NB console logs and other logs indicated a Java 11 environment. I removed the Java entry from the PATH and then had to restart NB 11. Everything worked fine.

Richard Jessop
  • 897
  • 1
  • 12
  • 19