Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: JavaFX runtime components are missing, and are required to run this application with Gradle example

Tags:

gradle

javafx

I know this has been asked multiple times... but I can't seem to find a solution.

Taken from this official guidelines example: https://openjfx.io/openjfx-docs/#gradle I went on and added in my build.gradle :

plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

javafx {
    version = '13'
    modules = ['javafx.controls']
}

repositories {
    mavenCentral()
}

mainClassName = "MyImage"

jar {
    manifest {
        attributes "Main-Class": "$mainClassName"
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

which, by running gradle jar (or gradle build), should actually produce a jar which should include all the packages it builds it with, that is the entire javafx library.

However, when it builds successfully and then I proceed with running:

java -jar build/libs/MyImage.jar

it still throws the error:

Error: JavaFX runtime components are missing, and are required to run this application

What am I missing?

(I use JDK 11)

Many Thanks.

like image 820
Eos Antigen Avatar asked Oct 23 '25 11:10

Eos Antigen


1 Answers

In Java 11 the Java launcher detects that you're extending javafx.application.Application and checks the modules are present. If you're using plain old JARs then you'll get the error

Error: JavaFX runtime components are missing, and are required to run this application

You have two choices. Setup your application to use the Java module system or the following workaround.

This workaround avoids the Java launcher check and will let the application run.

public class MyImage {   // <=== note - does not extend Application

    public static class YourRealApplication extends Application {

        @Override
        public void start(Stage primaryStage) throws Exception {
            // whatever...
        }

    }

    public static void main(String[] args) {
        Application.launch(YourRealApplication.class);
    }

}
like image 74
Adam Avatar answered Oct 26 '25 07:10

Adam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!