I have a java 8 Project with java fx. I recently switched to Java11 and OpenJFX11.
Everything runs fine with gradle run or with JVM arguments. But as soon as I build a jar, the executable jar will not execute because of this error:
Error: Could not find or load main class sample.application.main.SampleAppLauncher
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.7.0'
classpath 'org.openjfx:javafx:11'
}
repositories {
mavenLocal()
mavenCentral()
}
}
plugins {
id 'java'
id 'java-library'
id 'maven-publish'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
sourceCompatibility = 11
targetCompatibility = 11
repositories {
jcenter()
mavenCentral()
}
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier.set("sources")
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set("javadoc")
from javadoc.destinationDir
}
mainClassName="sample.application.main.Launcher"
publishing {
publications {
mavenAar(MavenPublication) {
from components.java
afterEvaluate {
artifact javadocJar
artifact sourcesJar
}
}
}
}
javafx {
version = "11"
modules = [ 'javafx.controls', 'javafx.fxml','javafx.graphics']
}
sourceSets {
main.java.srcDir "src/main/java"
main.resources.srcDir "src/main/resources"
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:27.0.1-jre'
testImplementation 'junit:junit:4.12'
implementation 'org.openjfx:javafx:11'
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
compile group: 'org.reflections', name: 'reflections', version: '0.9.11'
compile group: 'org.openjfx', name: 'javafx', version: '11'
}
jar {
manifest {
attributes(
'Main-Class': 'sample.application.main.Launcher'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Do I need to define something more for a regular Jar Build ? I the only way I know right now is to run the Application with JVM arguments with the path to my openjfx-11 . But this won't work on any other system that does not have JavaFX11.
I thought it would be compiled by gradle like every other dependecy into the jar.
Is there something differend about JFX11 ?
EDIT:
Application Class:
public class SampleAppLauncher extends Application {
@Override
public void start(Stage stage) throws Exception {
\\... startup
}
}
The Launcher:
public class Launcher {
public static void main(String[] args) {
SampleAppLauncher.launch(args);
}
}
Module info
module FXproject {
requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
opens sample.application.main to javafx.fxml;
exports sample.application.main;
}