I have rewritten my little Java 8 project from simple jar to single module in Java 11. In past I was building jar with Gradle and it was compatible with Windows and Linux. Now I configured Gradle to build my module and create custom runtime image and it is working but only on Linux. My custom runtime image contains only Linux libraries. Is there possibility to build image for Windows on Linux? I know I could open my project on Windows and create there image but I would like to keep my project on single OS. Here is my Gradle build:
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'
}
I added to build.gradle lines, before fire jlinkWin task I run clean task:
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'
}
Updated code above which creates custom runtime image for Windows but with out JavaFX libs.