我正在使用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 /上,它似乎仍然可以运行,那就更令人困惑了
我如何将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>
答案 0 :(得分:0)
看着2年的距离,我意识到我的问题实际上是“我希望Launch4J表现得像蝙蝠文件一样”。对于linux版本,我使用了与bat,sh文件等等效的linux,回想起来,我应该在Windows版本中也这样做。
launch4j的bundledJrePath配置告诉launch4j在哪里可以找到JRE,而不是在哪里放置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
我的文件夹结构最终像这样