I have a very simple Java class, src/main/java/webbrowser/WebBrowser.java
:
package webbrowser;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.scene.web.WebEngine;
import javafx.stage.Stage;
public class WebBrowser extends Application {
@Override
public void start(Stage stage) {
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.load("http://www.oracle.com");
Scene scene = new Scene(browser, 1200, 900);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
I have a pom.xml
file that lists the JavaFX dependencies and configures the assembly plugin:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>webbrowser</groupId>
<artifactId>WebBrowser</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>WebBrowser</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>18-ea+9</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>18-ea+9</version>
</dependency>
</dependencies>
<build>
<finalName>WebBrowser</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<mainClass>
webbrowser.WebBrowser
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
When I run on the command-line, mvn clean install assembly:single
, it says "BUILD SUCCESS" and there are no warnings or errors in the log.
Then I run:
% java -jar target/WebBrowser-jar-with-dependencies.jar
Error: JavaFX runtime components are missing, and are required to run this application
For some reason, the mvn assembly:single plugin did not include every JavaFX dependency.
However, when I run this on the command-line, it works fine and launches the application:
% java --module-path $JAVAFX --add-modules javafx.controls,javafx.web -jar target/WebBrowser-jar-with-dependencies.jar
Questions
- Why does the assembly:single goal not package the javafx.controls and javafx.web dependencies inside
target/WebBrowser-jar-with-dependencies.jar
? - How can I configure the Assembly plugin to include the javafx.controls and javafx.web dependencies inside an all-in-one, runnable
target/WebBrowser-jar-with-dependencies.jar
file?