yesterday I created a JavaFX project and I don't know why but when I want to run the app with commands java says:
Gradle task : build
Command : java -jar "name_of_the_file.jar"
Error: Could not find or load main class com.example.HelloApplication
Caused by: java.lang.NoClassDefFoundError:javafx/application/Application
but I can run it using gradlew run
module-info.java file
module com.example{
requires javafx.controls;
requires javafx.fxml;
opens com.example ;
exports com.example;
}
Manifest.MF file
Manifest-Version: 1.0
Main-Class: com.example.HelloApplication
build.gradle file
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
}
group 'com.example'
version '1.0-SNAPSHOT'
jar{
manifest{
attributes ('Main-Class' : 'com.example.HelloApplication' )
}
}
repositories {
mavenCentral()
}
ext {
junitVersion = '5.8.2'
}
sourceCompatibility = '17'
targetCompatibility = '17'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.example'
mainClass = 'com.example.jfx.HelloApplication'
}
javafx {
version = '17.0.2'
modules = ['javafx.controls', 'javafx.fxml']
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}
test {
useJUnitPlatform()
}
jlink {
imageZip = project.file("${buildDir}/distributions/app-${javafx.platform.classifier}.zip")
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
launcher {
name = 'app'
}
}
jlinkZip {
group = 'distribution'
}
and project structure
I am using inteliij idea community and my operating system is windows I really don't know what is wrong it seems all correct to me. Strange