0

UPD. The solution can be found here. Works for both maven and gradle. It is best to use a modular architecture.

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) }
    }
}

Project structure (image)

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

Jar archive structure.

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.

Santa Monica
  • 332
  • 3
  • 11
  • 1
    it is actually an executable, but you'll need to add JavaFX runtime components, just as the error message indicates – Stultuske Jun 18 '21 at 11:21
  • @Stultuske How exactly do you do this? And why in the documentation I followed, everything starts without this step? – Santa Monica Jun 18 '21 at 11:28
  • did you check the "getting started with gluon mobile" part? – Stultuske Jun 18 '21 at 11:31
  • @Stultuske where is the mobile application? I added runtime components in dependencies. – Santa Monica Jun 18 '21 at 11:33
  • it's at the start of the tutorial you say you followed – Stultuske Jun 18 '21 at 11:34
  • @Stultuske I am not trying to run this application on a mobile device. [lI am following the path runtime images -> Non-Modular project.](https://openjfx.io/openjfx-docs/) – Santa Monica Jun 18 '21 at 11:38
  • do you have javafx installed? – Stultuske Jun 18 '21 at 11:42
  • @Stultuske The documentation says: _If you develop your JavaFX applications using Gradle, you don't have to download the JavaFX SDK. Just specify the modules and the versions you want in the build.gradle file, and the build system will download the required modules, including the native libraries for your platform._. Yes, I tried loading javafx sdk and javafx mods, setting up environment variables. This had no effect. – Santa Monica Jun 18 '21 at 11:48
  • it looks like you're not the first to run into issues with this. https://stackoverflow.com/questions/52578072/gradle-openjfx11-error-javafx-runtime-components-are-missing – Stultuske Jun 18 '21 at 11:55
  • @Stultuske Yes, thanks a lot, it helped me. Add your comment as an answer so I can mark it as a solution. – Santa Monica Jun 18 '21 at 12:06
  • if that link provided the answer you needed, it's best to mark it as duplicate – Stultuske Jun 18 '21 at 12:07

0 Answers0