0

I have a Java (JavaFX) application that has been built using Gradle on Laptop A. When I deploy it to Laptop B it fails to run throwing the following Exception:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.NoClassDefFoundError: javafx/fxml/FXMLLoader
    at main.Main.start(Main.java:85)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    ... 1 more
Caused by: java.lang.ClassNotFoundException: javafx.fxml.FXMLLoader
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 10 more

I used the gradle pluggin to build an executable jar. It also built a zip and tar file. The zip (and tar) file contains a bin directory with a script to run the application and a lib directory containing loads of jar files.

I had a previous issue

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

I found a solution here:

Maven Shade JavaFX runtime components are missing

I created a wrapper class with a main (non javafx) that calls the main (javafx).

My current problem:

Clean install of Linux Mint - 19.3 Cinnamon Kernal - 5.3.0-53-generic

gradle-6.0.1

Java version -

openjdk 11.0.7 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)

If I use the script from the (exploded) zip file:

./MyApp/bin/MyApp config.json

Or just execute the app:

java -jar MyApp.jar config.json

These both fail

Using the ZIP file content I explored the jar files gradle deployed.

MyApp.jar
* javafx-graphics-11.jar
* javafx-base-11.jar
javafx-controls-11-linux.jar 
javafx-graphics-11-linux.jar
javafx-base-11-linux.jar
joda-time-2.10.5.jar

The '*' files are proxies and only contain a MANIFEST. The 'linux' jars contain the JavaFX classes however NONE of the files contain: javafx.fxml.FXMLLoader

My - build.gradle

plugins {
  id 'application'
  id 'org.openjfx.javafxplugin' version '0.0.8'
}
javafx {
    version = "11"
    modules = [ 'javafx.controls' ]
}
repositories {
    mavenLocal()
    mavenCentral()
}
sourceCompatibility = '11'

[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

if (!hasProperty('mainClass')) {
    ext.mainClass = 'Main'
}
mainClassName = "Main"
run {
    args 'config.json'
}
dependencies {
    compile "joda-time:joda-time:2.10.5"
    testCompile "junit:junit:4.12"
}
jar {
    manifest {
        attributes 'Main-Class': 'Main'
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

Can any one please see what I am doing wrong. This application needs to run on a clean system with no expectetaions other than Java (preferably OpenJDK).

I would also like it to run on a Windows 10 platform so can anyone tell me how to get the gradle build to include the 'win' equivilant jar files:

javafx-controls-11-win.jar 
javafx-graphics-11-win.jar
javafx-base-11-win.jar

Kind Regards

Stuart

stuartdd
  • 3
  • 3

1 Answers1

3

In your javafx section of your build.gradle you need to include fxml module:

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

Note that I have had some odd problems with version "11" javafx on Linux so you may want to change that to 13 or 14. JavaFX version requires at least JDK 11 so you can bump up JavaFX version without changing your JDK.

maroc
  • 466
  • 2
  • 5
  • That worked, thank you for your prompt (and accurate) response. – stuartdd Jun 06 '20 at 20:52
  • Can you please tell me if this will now run on Windows 10 without update? I currently run on Windows 10 but I have the full JDK 11 with JavaFX installed and I do not have a 'clean' windows install. I need to run without that. – stuartdd Jun 06 '20 at 20:52
  • For JavaFX there are some platform specific modules you need to include to make a fat jar run on other platforms. See https://openjfx.io/openjfx-docs/#modular for details. Note that you need jdk 9 or higher for jlink and I think jdk 14 for launcher. – maroc Jun 07 '20 at 14:57
  • Thank for your help. I have marked this as answered (I think !). – stuartdd Jun 08 '20 at 11:27
  • Thanks. On that link there is a section for "Cross Platform Jar" that should be what you need. They link to a git hub project and you can find their build.gradle here: https://github.com/openjfx/samples/blob/master/CommandLine/Non-modular/Gradle/hellofx/build.gradle If you have any problems ask here or create a new question. – maroc Jun 08 '20 at 15:58