0

i am currently on my way to convert some of my projects from Oracle JDK8 + JavaFX8 to OpenJDK11 + OpenJFX11. At the moment im trying to understand how to use OpenJFX11 as library via maven. I used maven before, love the easy dependency management.

I understood it that way, that when i just add openjfx as pom dependencies maven handles it completely and i dont need to configure anything java module related.

This is the relevant part of my pom:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  [...]

  <dependencies>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.11.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.1</version>
    </dependency>

    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-base</artifactId>
      <version>11</version>
    </dependency>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-controls</artifactId>
      <version>11</version>
    </dependency>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-graphics</artifactId>
      <version>11</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>[My Mainclass]</mainClass>
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

As you see i initally want to have Log4J2 and the BAsic JavaFX modules as dependencies for my project. AS i already had problems with launching OpenJFX11 Apps via maven at all i stumbled up on this thread: Different behaviour between Maven & Eclipse to launch a JavaFX 11 app So i have my Entry main Class and my JavaFX extended Application class seperated from each other, only one calling the other to launch the application.

When i launch this project from the commandprompt via maven

mvn compile exec:java

It runs fine and the JavaFX Application pops up.

What i cant do right now is create an launch configuration inside eclipse which will start my application inside Eclipse so i can use the eclipse debugger for example. I tried to create a Maven launch configuration with exactly the same parameters: enter image description here

But when i launch this configuration it fails with the following stacktrace:

[WARNING] 
java.lang.NoSuchMethodError: <init>
    at com.sun.glass.ui.win.WinApplication.staticScreen_getScreens (Native Method)
    at com.sun.glass.ui.Screen.initScreens (Screen.java:412)
    at com.sun.glass.ui.Application.lambda$run$1 (Application.java:152)
    at com.sun.glass.ui.win.WinApplication._runLoop (Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3 (WinApplication.java:174)
    at java.lang.Thread.run (Thread.java:834)
[WARNING] 
java.lang.NoSuchMethodError: <init>
    at com.sun.glass.ui.win.WinApplication.staticScreen_getScreens (Native Method)
    at com.sun.glass.ui.Screen.initScreens (Screen.java:412)
    at com.sun.glass.ui.Application.lambda$run$1 (Application.java:152)
    at com.sun.glass.ui.win.WinApplication._runLoop (Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3 (WinApplication.java:174)
    at java.lang.Thread.run (Thread.java:834)
[WARNING] 
java.lang.NullPointerException
    at com.sun.prism.d3d.D3DPipeline.getAdapterOrdinal (D3DPipeline.java:205)
    at com.sun.javafx.tk.quantum.QuantumToolkit.assignScreensAdapters (QuantumToolkit.java:695)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runToolkit (QuantumToolkit.java:313)
    at com.sun.javafx.tk.quantum.QuantumToolkit.lambda$startup$10 (QuantumToolkit.java:258)
    at com.sun.glass.ui.Application.lambda$run$1 (Application.java:153)
    at com.sun.glass.ui.win.WinApplication._runLoop (Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3 (WinApplication.java:174)
    at java.lang.Thread.run (Thread.java:834)

This seems to me as there are native libraries or methods missing and nothing directly in my project. But normally the javafx dependency should automatically add the system natives (win in my case, it appears under maven dependencies).

All i found was this thread, but i cant really create a solution for my problem out of it: NoSuchMethodError: <init> in com.sun.glass.ui.win.WinApplication.staticScreen_getScreens

Thanks in advance

Mattizin
  • 350
  • 1
  • 6
  • 19
  • 1
    What Eclipse version are you using? I'm on 2018-09 (4.9), and using both an Application class or a Launcher class, I can run and debug the JavaFX project from within Eclipse, as Run/Debug Maven build. With the launcher I can also run/debug as a Java Application. – José Pereda Oct 16 '18 at 21:59
  • What exactly do you mean with "and using both an Application class or a Launcher class". Im using Version: 2018-09 (4.9.0) Build id: 20180917-1800 Package for Java Developers + the Plugins e(fx)clipse and Java 11 Patch. The problem for me seems to be that when i launch it from in eclipse it seems to be using the wrong native or jdk libraries (i HAve JDK 8 and 11 installed), but i pointed the maven installation towards 11 and outisde eclipse it works... – Mattizin Oct 17 '18 at 07:20
  • 1
    I meant that you can set your main class extending Application, as usual, or also you can do a launcher class that doesn't extend Application, and set it as main class in your pom (so you can run later on a fat jar). Either way, from Eclipse both approaches work to me. Make sure your JDK 11 path is correct and that the project uses it. I have several JDKs installed, that's not the issue. – José Pereda Oct 17 '18 at 08:22
  • OK, i deinstalled all java instances and eclipse from my system. Reinstalled eclipse and it seems to be working like a charm now. Probably was a environment problem causing eclipse to launch with the worng native libraries. – Mattizin Oct 17 '18 at 10:14

1 Answers1

1

OK, i deinstalled all java instances and eclipse from my system. Reinstalled eclipse and it seems to be working like a charm now. Probably was a environment problem causing eclipse to launch with the worng native libraries.

Mattizin
  • 350
  • 1
  • 6
  • 19