【问题标题】:JavaFX Self-Contained Application Packaging for Mac without JRE没有 JRE 的 Mac 的 JavaFX 自包含应用程序打包
【发布时间】:2016-02-27 04:15:59
【问题描述】:

我有一个 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?

为了完整起见,我使用的是适用于 Mac 的 Oracle JDK 1.8.0_66。

【问题讨论】:

    标签: macos ant gradle javafx javafx-8


    【解决方案1】:

    这个 bug 从 java 1.8.0 update 60 开始存在,我已经报告了这个但它还不是正式的 bug。

    问题是内部打包器现在使用INI-file-format,你可以看到my findings here

    您应该能够使用值“prop”(like here)设置捆绑参数“launcher-cfg-format”

    免责声明:我是 javafx-maven-plugin 的维护者......并且不使用 gradle,但据我所知应该添加:

            <fx:bundleArgument arg="launcher-cfg-format" value="prop"/>
    

    【讨论】:

    • 这就是解决方案。使用您的建议,我已经解决了问题here。非常感谢 FibreFox!
    • 只是一个提示:它现在是 java 8java 9 的官方错误
    • 如何使用插件或在 maven 中设置?
    • @cosbor11 使用 javafx-maven-plugin 或 javafx-gradle-plugin 时不需要设置,它会在这些插件中自动完成。只需确保使用最新版本即可。此错误已在 1.8.0u92 中修复。
    猜你喜欢
    • 2017-01-28
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    • 1970-01-01
    相关资源
    最近更新 更多