我重写我的小Java 8项目从简单的jar到单个模块在Java 11。 在过去我和Gradle构建jar兼容Windows和Linux。 现在我配置Gradle构建模块和创建自定义运行时图像,但只有在Linux上工作。 我的自定义运行时图像仅包含Linux库。 有可能在Linux上构建图像为Windows ? 我知道我可以打开我的项目在Windows和创建图像但我想保持我的项目单一的操作系统。 这是我Gradle构建:
<span style="color:#393318"><code><span style="color:#303336">plugins </span><span style="color:#303336">{</span><span style="color:#303336">
id </span><span style="color:#7d2727">'application'</span><span style="color:#303336">
id </span><span style="color:#7d2727">'org.openjfx.javafxplugin'</span><span style="color:#303336"> version </span><span style="color:#7d2727">'0.0.5'</span>
<span style="color:#303336">}</span><span style="color:#303336">
group </span><span style="color:#7d2727">'eu.sample'</span><span style="color:#303336">
version </span><span style="color:#7d2727">'2.0'</span><span style="color:#303336">
repositories </span><span style="color:#303336">{</span><span style="color:#303336">
mavenCentral</span><span style="color:#303336">()</span>
<span style="color:#303336">}</span><span style="color:#303336">
javafx </span><span style="color:#303336">{</span><span style="color:#303336">
modules </span><span style="color:#303336">=</span> <span style="color:#303336">[</span> <span style="color:#7d2727">'javafx.controls'</span><span style="color:#303336">,</span> <span style="color:#7d2727">'javafx.fxml'</span> <span style="color:#303336">]</span>
<span style="color:#303336">}</span><span style="color:#303336">
mainClassName </span><span style="color:#303336">=</span> <span style="color:#7d2727">"$moduleName/eu.sample.app.Main"</span><span style="color:#303336">
def java_home </span><span style="color:#303336">=</span><span style="color:#303336"> hasProperty</span><span style="color:#303336">(</span><span style="color:#7d2727">'org.gradle.java.home'</span><span style="color:#303336">)</span> <span style="color:#303336">?</span><span style="color:#303336"> getProperty</span><span style="color:#303336">(</span><span style="color:#7d2727">'org.gradle.java.home'</span><span style="color:#303336">)</span> <span style="color:#303336">:</span> <span style="color:#2b91af">System</span><span style="color:#303336">.</span><span style="color:#303336">getenv</span><span style="color:#303336">(</span><span style="color:#7d2727">'JAVA_HOME'</span><span style="color:#303336">)</span><span style="color:#303336">
def fx_jmods </span><span style="color:#303336">=</span><span style="color:#303336"> hasProperty</span><span style="color:#303336">(</span><span style="color:#7d2727">'path.to.fx.mods'</span><span style="color:#303336">)</span> <span style="color:#303336">?</span><span style="color:#303336"> getProperty</span><span style="color:#303336">(</span><span style="color:#7d2727">'path.to.fx.mods'</span><span style="color:#303336">)</span> <span style="color:#303336">:</span> <span style="color:#2b91af">System</span><span style="color:#303336">.</span><span style="color:#303336">getenv</span><span style="color:#303336">(</span><span style="color:#7d2727">'PATH_TO_FX_MODS'</span><span style="color:#303336">)</span><span style="color:#303336">
dependencies </span><span style="color:#303336">{</span>
<span style="color:#303336">}</span><span style="color:#303336">
task jlink</span><span style="color:#303336">(</span><span style="color:#303336">type</span><span style="color:#303336">:</span> <span style="color:#2b91af">Exec</span><span style="color:#303336">)</span> <span style="color:#303336">{</span><span style="color:#303336">
dependsOn </span><span style="color:#7d2727">'clean'</span><span style="color:#303336">
dependsOn </span><span style="color:#7d2727">'jar'</span><span style="color:#303336">
workingDir </span><span style="color:#7d2727">'build'</span>
<span style="color:#101094">if</span> <span style="color:#303336">(</span><span style="color:#303336">java_home </span><span style="color:#303336">==</span> <span style="color:#101094">null</span><span style="color:#303336">)</span> <span style="color:#303336">{</span>
<span style="color:#101094">throw</span> <span style="color:#101094">new</span> <span style="color:#2b91af">RuntimeException</span><span style="color:#303336">(</span><span style="color:#7d2727">"java_home is not defined."</span><span style="color:#303336">)</span>
<span style="color:#303336">}</span>
<span style="color:#101094">if</span> <span style="color:#303336">(</span><span style="color:#303336">fx_jmods </span><span style="color:#303336">==</span> <span style="color:#101094">null</span><span style="color:#303336">)</span> <span style="color:#303336">{</span>
<span style="color:#101094">throw</span> <span style="color:#101094">new</span> <span style="color:#2b91af">RuntimeException</span><span style="color:#303336">(</span><span style="color:#7d2727">"fx_jmods is not defined."</span><span style="color:#303336">)</span>
<span style="color:#303336">}</span><span style="color:#303336">
commandLine </span><span style="color:#7d2727">"${java_home}/bin/jlink"</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--module-path'</span><span style="color:#303336">,</span> <span style="color:#7d2727">"libs${File.pathSeparatorChar}${fx_jmods}"</span><span style="color:#303336">,</span>
<span style="color:#7d2727">'--add-modules'</span><span style="color:#303336">,</span> <span style="color:#7d2727">"${moduleName}"</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--output'</span><span style="color:#303336">,</span> <span style="color:#7d2727">"${moduleName}"</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--strip-debug'</span><span style="color:#303336">,</span>
<span style="color:#7d2727">'--compress'</span><span style="color:#303336">,</span> <span style="color:#7d2727">'2'</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--no-header-files'</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--no-man-pages'</span>
<span style="color:#303336">}</span></code></span>
我添加了。 gradle行,之前火jlinkWin任务我运行清洁任务:
<span style="color:#393318"><code><span style="color:#303336">task jlinkWin</span><span style="color:#303336">(</span><span style="color:#303336">type</span><span style="color:#303336">:</span> <span style="color:#2b91af">Exec</span><span style="color:#303336">)</span> <span style="color:#303336">{</span><span style="color:#303336">
dependsOn </span><span style="color:#7d2727">'clean'</span><span style="color:#303336">
dependsOn </span><span style="color:#7d2727">'jar'</span><span style="color:#303336">
workingDir </span><span style="color:#7d2727">'build'</span>
<span style="color:#101094">if</span> <span style="color:#303336">(</span><span style="color:#303336">java_home </span><span style="color:#303336">==</span> <span style="color:#101094">null</span><span style="color:#303336">)</span> <span style="color:#303336">{</span>
<span style="color:#101094">throw</span> <span style="color:#101094">new</span> <span style="color:#2b91af">RuntimeException</span><span style="color:#303336">(</span><span style="color:#7d2727">"java_home is not defined."</span><span style="color:#303336">)</span>
<span style="color:#303336">}</span>
<span style="color:#101094">if</span> <span style="color:#303336">(</span><span style="color:#303336">fx_jmods </span><span style="color:#303336">==</span> <span style="color:#101094">null</span><span style="color:#303336">)</span> <span style="color:#303336">{</span>
<span style="color:#101094">throw</span> <span style="color:#101094">new</span> <span style="color:#2b91af">RuntimeException</span><span style="color:#303336">(</span><span style="color:#7d2727">"fx_jmods is not defined."</span><span style="color:#303336">)</span>
<span style="color:#303336">}</span><span style="color:#303336">
commandLine </span><span style="color:#7d2727">"${java_home}/bin/jlink"</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--module-path'</span><span style="color:#303336">,</span> <span style="color:#7d2727">"/home/user1/Download/win-jdk-11.0.1/jmods${File.pathSeparatorChar}libs${File.pathSeparatorChar}${fx_jmods}"</span><span style="color:#303336">,</span>
<span style="color:#7d2727">'--add-modules'</span><span style="color:#303336">,</span> <span style="color:#7d2727">"${moduleName}"</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--output'</span><span style="color:#303336">,</span> <span style="color:#7d2727">"${moduleName}"</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--strip-debug'</span><span style="color:#303336">,</span>
<span style="color:#7d2727">'--compress'</span><span style="color:#303336">,</span> <span style="color:#7d2727">'2'</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--no-header-files'</span><span style="color:#303336">,</span> <span style="color:#7d2727">'--no-man-pages'</span>
<span style="color:#303336">}</span></code></span>
好吧我发现解决方案。 更新的代码上面创建自定义运行时图像窗口。