【发布时间】:2019-05-14 10:20:24
【问题描述】:
我已经将我的 Java 8 小项目从简单的 jar 重写为 Java 11 中的单个模块。过去我使用 Gradle 构建 jar,它与 Windows 和 Linux 兼容。现在我配置了 Gradle 来构建我的模块并创建自定义运行时映像,它可以工作,但只能在 Linux 上运行。我的自定义运行时映像仅包含 Linux 库。是否有可能在 Linux 上为 Windows 构建映像?我知道我可以在 Windows 上打开我的项目并在那里创建图像,但我想将我的项目保留在单个操作系统上。 这是我的 Gradle 构建:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
group 'eu.sample'
version '2.0'
repositories {
mavenCentral()
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = "$moduleName/eu.sample.app.Main"
def java_home = hasProperty('org.gradle.java.home') ? getProperty('org.gradle.java.home') : System.getenv('JAVA_HOME')
def fx_jmods = hasProperty('path.to.fx.mods') ? getProperty('path.to.fx.mods') : System.getenv('PATH_TO_FX_MODS')
dependencies {
}
task jlink(type: Exec) {
dependsOn 'clean'
dependsOn 'jar'
workingDir 'build'
if (java_home == null) {
throw new RuntimeException("java_home is not defined.")
}
if (fx_jmods == null) {
throw new RuntimeException("fx_jmods is not defined.")
}
commandLine "${java_home}/bin/jlink", '--module-path', "libs${File.pathSeparatorChar}${fx_jmods}",
'--add-modules', "${moduleName}", '--output', "${moduleName}", '--strip-debug',
'--compress', '2', '--no-header-files', '--no-man-pages'
}
我添加到 build.gradle 行,在触发 jlinkWin 任务之前我运行 clean 任务:
task jlinkWin(type: Exec) {
dependsOn 'clean'
dependsOn 'jar'
workingDir 'build'
if (java_home == null) {
throw new RuntimeException("java_home is not defined.")
}
if (fx_jmods == null) {
throw new RuntimeException("fx_jmods is not defined.")
}
commandLine "${java_home}/bin/jlink", '--module-path', "/home/user1/Download/win-jdk-11.0.1/jmods${File.pathSeparatorChar}libs${File.pathSeparatorChar}${fx_jmods}",
'--add-modules', "${moduleName}", '--output', "${moduleName}", '--strip-debug',
'--compress', '2', '--no-header-files', '--no-man-pages'
}
更新了上面的代码,它为 Windows 创建了自定义运行时映像,但没有 JavaFX 库。
【问题讨论】:
-
这与 gradle 无关,但可能会有所帮助:stackoverflow.com/questions/47593409/…
-
@ernest_k 这是有用的信息,谢谢。我没有找到这个。
-
您需要在您的发行版中包含 Windows 库和 Linux 库。
-
问题未解决。我无法在 Windows 上运行图像。图片中没有JavaFX的dll库。