I am trying to create an executable jar file from this tutorial.
I am creating a non-modular Java application like in the tutorial.
- Java 16
- Gradle 7.1
Build.gradle file structure (Took it from the official openfx documentation):
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
repositories {
mavenCentral()
}
javafx {
version = "16"
modules = [ 'javafx.controls', 'javafx.base','javafx.graphics' ]
}
dependencies {
runtimeOnly "org.openjfx:javafx-graphics:16:win"
runtimeOnly "org.openjfx:javafx-base:16:win"
runtimeOnly "org.openjfx:javafx-controls:16:win"
}
mainClassName = 'hellofx.Launch'
jar {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
manifest {
attributes (
'Main-Class': 'hellofx.Launch'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Launch.java
package hellofx;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class Launch extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new AnchorPane());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I can run my application and it works.
gradlew.bat run
I can build the jar file.
C:\...\fx2000>gradle.bat jar
> Configure project :
Project : => no module-info.java found
BUILD SUCCESSFUL in 706ms
2 actionable tasks: 2 up-to-date
But if I try to run my jar file, I get this:
C:\...\fx2000>java -jar build/libs/fx2000.jar
Error: JavaFX runtime components are missing, and are required to run this application
I understand that the problem lies in the modularity of java. But, I followed the the documentation step by step.
Manifest file:
Manifest-Version: 1.0
Main-Class: hellofx.Launch
Javafx folder in fx2000.jar archive (folder generated automatically)
What am I doing wrong? I would like to understand the reason and not find a simple solution.