简体   繁体   English

使用 jlink 构建和部署 JavaFX Applicationn

[英]Build and deploy JavaFX Applicationn with jlink

I have a script build.gradle, which created the IDEA development environment when creating a JavaFX project with Gradle support:我有一个脚本 build.gradle,它在创建支持 Gradle 的 JavaFX 项目时创建了 IDEA 开发环境:

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. “build”任务完成后,build文件夹中出现“distributions”文件夹。 It contains a zip archive with the following contents:它包含一个包含以下内容的 zip 存档:

bin 和 lib 文件夹

The bin folder contains two scripts, sh and bat. bin 文件夹包含两个脚本,sh 和 bat。 The lib folder contains, as I understand it, all the required jar modules.据我了解,lib 文件夹包含所有必需的 jar 模块。 If JAVA_HOME is installed on Java 17 in my environment, then when executing the bat script, my program starts.如果 JAVA_HOME 在我的环境中安装在 Java 17 上,那么在执行 bat 脚本时,我的程序就会启动。 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.我希望 jlink 是一种对用户更友好的应用程序组装和打包的类似物,这将有助于创建类似于 exe 应用程序启动器的东西。

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.我还注意到在 build.gradle 中没有与 jlink 相关的任务,在使用“build”任务的构建过程中没有被调用。 在此处输入图像描述

I tried to run them myself, and I got the same error:我试图自己运行它们,但我得到了同样的错误: 在此处输入图像描述

I am confused by the mention of the "distributions/app" path in build.gradle, I expect there should be something else after the build.我对 build.gradle 中提到的“distributions/app”路径感到困惑,我希望在构建之后应该还有其他东西。

What am I doing wrong?我究竟做错了什么? What should I get at the output using jlink ?我应该使用 jlink 在输出中得到什么?

The problem is solved.问题已经解决了。

The exclude of the org.openjfx module was removed from all dependencies. org.openjfx模块的排除已从所有依赖项中删除。

Useful links:有用的链接:

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

https://github.com/openjfx/samples https://github.com/openjfx/samples

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM