I have a JavaFX application that properly runs with Maven:
mvn compile
mvn exec:java # Launches the GUI
This is on Ubuntu, using openjdk-11-jdk
, maven
and openjfx
Ubuntu packages.
I want to compile and run this application from the Eclipse IDE (eclipse installed with sudo snap install --classic eclipse
). I have the m2e (Maven to Eclipse) plugin installed, and imported the project with File -> Import -> Maven -> Existing Maven Project
. For non-JavaFX projects, the m2e plugin does everything needed to configure the project in Eclipse from Maven's pom.xml
. Unfortunately, in my case, something is missing: typechecking works properly and finds the javafx.*
classes, but when I try to run the application, I get the following error message in the console:
Error: JavaFX runtime components are missing, and are required to run this application
A workaround is to run the application as a Maven application (Run -> Run As -> Maven Build -> target=exec:java
), but I find it less convenient and slower, so I'm looking for a way to get the application to run directly as a Java application in Eclipse.
I found the way to configure Eclipse manually (posted below as an answer), but I'm still wondering whether there's a better way, that would let Maven + m2e do the job completely, i.e. as much as possible configure everything from pom.xml
and have everything "just work" in Eclipse.
The problem can be reproduced on a minimalist example, with this pom.xml
:
<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>
<groupId>jfxpl</groupId>
<artifactId>jfxpl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.2</version>
<configuration>
<mainClass>App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<mainClass>App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
And any application using JavaFX like:
import javafx.application.Application;
import javafx.stage.Stage;
public class App extends Application {
@Override
public void start(Stage stage) throws Exception {
System.out.println("Start!"); // Or real JavaFX stuff here obviously
}
public static void main(String[] args) {
Application.launch(args);
}
}