Home > database >  Build and deploy JavaFX Applicationn with jlink
Build and deploy JavaFX Applicationn with jlink

Time:06-13

I have a script build.gradle, which created the IDEA development environment when creating a JavaFX project with Gradle support:

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.10'
    id 'org.beryx.jlink' version '2.24.4'
    id 'org.javamodularity.moduleplugin' version '1.8.10' apply false
}

group 'com.prototype'
version '1.0'

repositories {
    mavenCentral()
}

ext {
    junitVersion = '5.8.2'
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
    sourceCompatibility = '17'
    targetCompatibility = '17'
}

application {
    mainModule = 'com.prototype.simulationcrystalgrowth'
    mainClass = 'com.prototype.simulationcrystalgrowth.SimulationApplication'
}

javafx {
    version = '17.0.1'
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web']
}

dependencies {
    implementation('org.controlsfx:controlsfx:11.1.1')
    implementation('com.dlsc.formsfx:formsfx-core:11.4.2') {
        exclude(group: 'org.openjfx')
    }
    implementation('net.synedra:validatorfx:0.2.1') {
        exclude(group: 'org.openjfx')
    }
    implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
    implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
    implementation('eu.hansolo:tilesfx:17.0.11') {
        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'
}

After the "build" task is completed, the "distributions" folder appears in the build folder. It contains a zip archive with the following contents:

bin and lib folders

The bin folder contains two scripts, sh and bat. The lib folder contains, as I understand it, all the required jar modules. If JAVA_HOME is installed on Java 17 in my environment, then when executing the bat script, my program starts. I expected that jlink is a kind of analogue of a more user-friendly assembly and packaging of the application, which will help to create something like an exe application launcher.

I also noticed that there are no tasks related to jlink in build.gradle is not called during the build process using the "build" task. enter image description here

I tried to run them myself, and I got the same error: enter image description here

I am confused by the mention of the "distributions/app" path in build.gradle, I expect there should be something else after the build.

What am I doing wrong? What should I get at the output using jlink ?

CodePudding user response:

The problem is solved.

The exclude of the org.openjfx module was removed from all dependencies.

Useful links:

https://openjfx.io/openjfx-docs/#gradle

https://github.com/openjfx/samples

https://developer.tizen.org/development/articles/openjdk-and-openjfx-installation-guide

  • Related