Been stuck with this issue for days. I'm trying to export a jar file using the gradle build command but it provides a small jar file. When I run the jar file it gives the following error, indicating that the javafx dependency was not included in the build:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012) at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) at newcare.home.Main_1.main(Main_1.java:6) Caused by: java.lang.ClassNotFoundException: javafx.application.Application at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ... 10 more I've seen posts such as this Creating a Java Gradle project and building the .jar file in IntelliJ IDEA - How to? They seem to help others but not me. Here's my build.gradle:
plugins { id 'java' id 'application' id 'org.openjfx.javafxplugin' version '0.0.8' } group 'newcare' version '1.0-SNAPSHOT' repositories { mavenCentral() } sourceCompatibility = 1.8 dependencies { testImplementation group: 'junit', name: 'junit', version: '4.12' implementation group: 'org.jasypt', name: 'jasypt', version: '1.9.2' implementation 'com.google.code.gson:gson:2.8.7' implementation 'joda-time:joda-time:2.10.13' implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final' // here starts JavaFX implementation 'org.openjfx:javafx:14' implementation 'org.openjfx:javafx-base:14' implementation 'org.openjfx:javafx-graphics:14' implementation 'org.openjfx:javafx-controls:14' implementation 'org.openjfx:javafx-fxml:14' implementation 'org.openjfx:javafx-swing:14' implementation 'org.openjfx:javafx-media:14' implementation 'org.openjfx:javafx-web:14' } javafx{ modules = ['javafx.controls', 'javafx.fxml', 'javafx.media', 'javafx.graphics'] version = '11.0.2' } mainClassName = 'newcare.home.Main_1' jar { from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } manifest { attributes "Main-Class": "$mainClassName" } exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA' } sourceSets { main { resources { srcDirs = ["src/main/java"] includes = ["**/*.fxml","**/*.css","**/*.png","**/*.jpg"] } } } I've also tried to use the build artifacts methods but nothing seems to work.
dependencies(you'd use thejavafxextension to declare which modules you want, and the version; see the documentation for details). And why use JavaFX 14 when version 17.0.1 is the latest release? Note the latest version for the JavaFX plugin is 0.0.10.