我有一个JavaFX 8桌面应用程序,我正在创建一个.app
应用程序包,以将应用程序分发给Mac用户。为了减小大小,我创建了一个不包含JRE的包(用户必须安装Java才能使用生成的包)。
我的构建是一个Gradle脚本,但由于Oracle“自包含应用程序打包”工具与Ant一起使用,我按如下方式调用Ant脚本:
ant.importBuild 'mac-bundle-ant.xml'
Ant脚本本身就是这样的:
<project name="VocabHunter Packaging" basedir=""
xmlns:fx="javafx:com.sun.javafx.tools.ant">
<property environment="env"/>
<property name="JAVA_HOME" value="${env.JAVA_HOME}"/>
<target name="jfxbundle" description="Build the application bundle">
<taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
uri="javafx:com.sun.javafx.tools.ant"
classpath="${JAVA_HOME}/lib/ant-javafx.jar"/>
<fx:application id="VocabHunterId"
name="VocabHunter"
mainClass="io.github.vocabhunter.gui.distribution.PackagedVocabHunter"/>
<fx:resources id="applicationResourcesId">
<fx:fileset dir="${basedir}/build/libs"/>
</fx:resources>
<fx:deploy outdir="${basedir}/build"
nativeBundles="image">
<fx:platform basedir=""/>
<fx:application refId="VocabHunterId"/>
<fx:resources refid="applicationResourcesId"/>
<fx:info title="VocabHunter">
<fx:association description="VocabHunter session"
extension="wordy"
mimetype="application/x-vnd.VocabHunterSession"
icon="${basedir}/icons/mac/VocabHunterSession.icns"/>
</fx:info>
<fx:bundleArgument arg="icon"
value="${basedir}/icons/mac/VocabHunter.icns"/>
</fx:deploy>
</target>
</project>
问题是生成的.app
包不起作用。展望未来,我在Contents/Java/VocabHunter.cfg
中找到了以下有问题的行:
app.runtime=$APPDIR/PlugIns/Java.runtime
如果我删除了这一行,那么.app
包就会按预期工作。现在我已经在我的Gradle脚本中添加了以下hack来解决这个问题:
jfxbundle.doLast {
FileTree tree = fileTree(dir: 'build/bundles').include('**/*.cfg')
tree.each {File file ->
String content = file.text.replaceAll('(?m)^app\\.runtime=.*$\n', '')
file.write(content)
}
}
您可以看到完整代码here。
有谁知道如何修复Ant脚本,从而避免了Gradle文件中的hack需要?
为了完整性,我使用Oracle JDK 1.8.0_66 for Mac。
答案 0 :(得分:2)
这个bug开始存在于java 1.8.0 update 60中,我已经报告了这个但它还不是官方的bug。
问题是现在使用INI文件格式的内部打包程序,您可以看到my findings here。
您应该能够使用值“prop”(like here)
设置bundle-argument“launcher-cfg-format”免责声明:我是javafx-maven-plugin的维护者......并且不使用gradle,但是我应该尽量添加:
<fx:bundleArgument arg="launcher-cfg-format" value="prop"/>