I'm using Gradle build system in intellij I tried to create an artifact and build jar in intellIj , but there are 3 issues i encountered:
1)go to project structure/artifacts create an jar with type JavaFX application. Entered path to main class. Artifact was created but faced with " Can't build artifact - fx:deploy isn't available in this JDK" (I'm using JDK 21)
Tried build a classic JAR .
no main manifest attribute, in D:\Projects\mobileExam\out\artifacts\mobileExam_jar\mobileExam.jar
.By the way i have an manifest in JAR.3)Created an jar artifact with selected option "JAR files from libraries copy to the output directory and link via manifest" then tried to launch JAR and got this error Invalid or corrupt jarfile D:\Projects\mobileExam\out\artifacts\mobileExam_jar2\mobileExam.jar
. Why gradle corrupted my JAR? I'm using gradle 8.5.
Here is my manifest:
Main-Class: com.english.mobileexam.mobileexam.Launch
Class-Path: junit-platform-engine-1.10.0.jar javafx-fxml-21-win.jar ikon
li-javafx-12.3.1.jar ikonli-core-12.3.1.jar formsfx-core-11.6.0.jar jun
it-platform-commons-1.10.0.jar javafx-swing-21-win.jar tilesfx-11.48.ja
r javafx-controls-21.jar bootstrapfx-core-0.4.0.jar javafx-controls-21-
win.jar javafx-base-21.jar javafx-base-21-win.jar javafx-graphics-21-wi
n.jar validatorfx-0.4.0.jar javafx-web-21-win.jar junit-jupiter-api-5.1
0.0.jar javafx-media-21.jar controlsfx-11.1.2.jar junit-jupiter-engine-
5.10.0.jar opentest4j-1.3.0.jar javafx-graphics-21.jar javafx-media-21-
win.jar
My build.gradle file
plugins {
id 'java'
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.12'
id 'org.openjfx.javafxplugin' version '0.0.13'
id 'org.beryx.jlink' version '2.25.0'
}
group 'com.english.mobileexam'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
junitVersion = '5.10.0'
}
sourceCompatibility = '21'
targetCompatibility = '21'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
application {
mainModule = 'com.english.mobileexam.mobileexam'
mainClass = 'com.english.mobileexam.mobileexam.HelloApplication'
}
javafx {
version = '21'
modules = ['javafx.controls', 'javafx.fxml', 'javafx.web', 'javafx.swing' ]
}
dependencies {
implementation('org.controlsfx:controlsfx:11.1.2')
implementation('com.dlsc.formsfx:formsfx-core:11.6.0') {
exclude(group: 'org.openjfx')
}
implementation('net.synedra:validatorfx:0.4.0') {
exclude(group: 'org.openjfx')
}
implementation('org.kordamp.ikonli:ikonli-javafx:12.3.1')
implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
implementation('eu.hansolo:tilesfx:11.48') {
exclude(group: 'org.openjfx')
}
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'
}
So, i just executed gradle task "jlink" in my project and got image in build/image then i run .bat file in image/bin and my app runs!
I wanted to create an executable build of my project. So , i don't need jar anymore. Credits to jewelsea!
Don't use intellij's build jar artifacts with javaFX and gradle build system, it's just broken.