0

I've created a JavaFX 11 app that is ready to be deployed.

I use Gradle 5.0 as my build tool and this command to compile the jar:

jar {
    manifest {
        attributes(
                'Main-Class': 'checkmydigitalfootprint.MainApp'
        )
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
 }

Then on command line I've tried different commands to run the jar file:

java -jar CheckMyDigitalFootprint.jar

java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls

java -jar CheckMyDigitalFootprint.jar --module-path="/users/joseph/eclipse-workspace/javafx-sdk-11.0.1/lib" --add-modules=javafx.controls --add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED --add-exports=javafx.base/com.sun.javafx.beans=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED --add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED

But all result in the same error:

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

Rest of build.gradle:

plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.0.5'
  id 'eclipse'
}

repositories {
    mavenCentral()
}

dependencies {
    /* uncomment for cross-platform jar: */
//    compile "org.openjfx:javafx-graphics:11:win"
//    compile "org.openjfx:javafx-graphics:11:linux"
    compile "org.openjfx:javafx-graphics:11:mac"
    compile 'com.jfoenix:jfoenix:9.0.8'
    compile 'org.json:json:20180813'
    compile 'com.google.api-client:google-api-client:1.23.0'
    compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
    compile 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'
    compile group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.1'
    compile 'com.sun.activation:javax.activation:1.2.0'  
    compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'
    testCompile "org.testfx:testfx-core:4.0.15-alpha"
    testCompile "org.testfx:testfx-junit:4.0.15-alpha"
}

javafx {
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

run {
    if (osdetector.os == 'windows') {
        // Temporal fix for Eclipse with JDK 1.8 and Windows 
        systemProperty "java.library.path", "C:\tmp"
    }
}

jar {
    manifest {
        attributes(
                'Main-Class': 'checkmydigitalfootprint.MainApp'
        )
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
 }

mainClassName = 'checkmydigitalfootprint.MainApp'
ZhaoGang
  • 4,491
  • 1
  • 27
  • 39
doctopus
  • 5,349
  • 8
  • 53
  • 105
  • On the command line, try putting the `-jar CheckMyDigitialFootprint.jar` bit at the end of the command. Running `java --help` says the format is: `java [options] -jar [args...]`. – Slaw Dec 13 '18 at 03:31
  • that solved it. Thanks ;) – doctopus Dec 13 '18 at 03:50
  • That's not a "fat" jar, if you still need to add some extra arguments to the command line. Are you adding a launcher class (like in [here](https://stackoverflow.com/questions/52569724/javafx-11-create-a-jar-file-with-gradle))? – José Pereda Dec 13 '18 at 08:04

4 Answers4

2

This is explained on official OpenJFX website

The solution is simple, just add following VM option:

--module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml

for your Gradle project apply JavaFX gradle plugin

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

add the required modules. e.g:

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

Specify version of JavaFX

javafx {
    version = "11.0.+"
}

Hopefully this will help you :)

ChrisF
  • 134,786
  • 31
  • 255
  • 325
2

You solve the problem by using this

Java -jar --module-path /path/to/javafx-sdk-11.0.1/lib --add-modules=javafx.controls,javafx.fxml (path to your jar file)

0

I have no experience with Gradle but was having the same problem with a runnable jar giving the "JavaFX runtime components are missing...". (Using openJDK/JFX 11.) Even when the vm arguments were correctly included in the command line. The problem was the "Library handling" option for building the runnable jar. "Extract required libraries.." didn't do the job. "Package required libraries..." was the correct option for building a runnable jar file with JavaFX dependency.

0

To also solve this problem..... You can create another main class aside the main class javafx provided and then call the javafx main class from the main class you created. In this way you can create an executable jar with all the javafx runtime module present and create an installer form the jar. This is mostly applicable when you are using any jdk above 8