[英]Bundling a JRE with a launch4j application in gradle
我正在使用 edu.sc.seis.launch4j 插件使用 gradle 構建腳本構建可分發的應用程序。 我正在嘗試使用捆綁的 JRE 生成這些。
這是gradle腳本
plugins {
id 'org.jetbrains.intellij' version '0.3.7'
id 'java'
id 'edu.sc.seis.launch4j' version '2.4.4'
}
group 'worldbuilders'
version '0.4.4-SNAPSHOT'
apply plugin: 'application'
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
}
mainClassName = 'hello.HelloWorld'
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
intellij {
version '2017.3.5'
}
launch4j {
bundledJrePath = "jre" //my jre to use is in the projectRoot/jre folder but I think that's not what this parameter is for anyway
mainClassName = 'hello.HelloWorld'
bundledJre64Bit = true
//icon = "${projectDir}/icons/myApp.ico"
}
令人沮喪的是,這會創建一個運行的應用程序(由 gradle 任務 createExe 創建的 exe),但顯然沒有捆綁在其中/旁邊的 JRE,大概是因為它運行是因為它回退到使用系統 jre,這使得測試變得困難. 如果我把故意損壞的jre放在/jre/它似乎仍然運行,這更令人困惑
如何將 JRE 與使用 gradle-launch4j 插件創建的 exe 發行版捆綁在一起? (而且實際上是由exe使用而不是使用系統jre)
插件創建的調試 XML(由 launch4j 使用):
使用命令gradle createExe -Pl4j-debug
<?xml version='1.0' encoding='UTF-8'?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>lib/onemillionworlds-0.4.4-SNAPSHOT.jar</jar>
<outfile>onemillionworlds.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon></icon>
<classPath>
<mainClass>hello.HelloWorld</mainClass>
<cp>lib\onemillionworlds-0.4.4-SNAPSHOT.jar</cp>
<cp>lib\tools.jar</cp>
<cp>lib\jme3-lwjgl-3.2.0-stable.jar</cp>
<cp>lib\jme3-desktop-3.2.0-stable.jar</cp>
<cp>lib\jme3-core-3.2.0-stable.jar</cp>
<cp>lib\lwjgl-2.9.3.jar</cp>
<cp>lib\lwjgl-platform-2.9.3-natives-windows.jar</cp>
<cp>lib\lwjgl-platform-2.9.3-natives-linux.jar</cp>
<cp>lib\lwjgl-platform-2.9.3-natives-osx.jar</cp>
<cp>lib\jinput-2.0.5.jar</cp>
<cp>lib\jutils-1.0.0.jar</cp>
<cp>lib\jinput-platform-2.0.5-natives-linux.jar</cp>
<cp>lib\jinput-platform-2.0.5-natives-windows.jar</cp>
<cp>lib\jinput-platform-2.0.5-natives-osx.jar</cp>
</classPath>
<jre>
<path>jre</path>
<bundledJre64Bit>true</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.8.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>jdkOnly</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>0.0.0.1</fileVersion>
<txtFileVersion>unspecified</txtFileVersion>
<fileDescription>onemillionworlds</fileDescription>
<copyright>unknown</copyright>
<productVersion>0.0.0.1</productVersion>
<txtProductVersion>unspecified</txtProductVersion>
<productName>onemillionworlds</productName>
<companyName></companyName>
<internalName>onemillionworlds</internalName>
<originalFilename>onemillionworlds.exe</originalFilename>
<trademarks></trademarks>
<language>ENGLISH_US</language>
</versionInfo>
</launch4jConfig>
以 2 年的距離來看這個,我意識到我的問題實際上是“我希望 Launch4J 的行為與 bat 文件完全一樣”。 對於 linux 版本,我使用了相當於 bat 的 linux 文件,一個 sh 文件,回想起來,我應該對 windows 版本也這樣做。
launch4j 的 bundledJrePath 配置告訴 launch4j 在哪里可以找到 JRE,而不是把它放在哪里,你必須單獨把它放在那里。 如果 launch4j 找不到它,它將使用已安裝的 JRE(或下載一個)。
我的相關 Gradle 配置最終是這樣的
launch4j { //used for windows
mainClassName = 'mygame.Main'
bundledJrePath = 'jre'
bundledJre64Bit = true
jreMinVersion = '11'
}
task packageExecutableDistribution(type: Zip) {
archiveName = "oneMillionWorlds.zip"
destinationDir = file("$buildDir/distExecutable")
from "$buildDir/launch4j"
}
task addJreToDistributable(type: Copy) {
from zipTree("resources/desktop-deployment/OpenJDK11U-jre_x64_windows_hotspot_11.0.4_11.zip")
destinationDir = file("$buildDir/launch4j")
}
packageExecutableDistribution.dependsOn createExe
packageExecutableDistribution.dependsOn addJreToDistributable
我的文件夾結構最終是這樣的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.