适用于 Mac 的 JavaFX 自包含应用程序打包,无需 JRE [英] JavaFX Self-Contained Application Packaging for Mac without JRE

查看:53
本文介绍了适用于 Mac 的 JavaFX 自包含应用程序打包,无需 JRE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JavaFX 8 桌面应用程序,我正在创建一个 .app 应用程序包以将应用程序分发给 Mac 用户.为了减小大小,我创建了一个不包含 JRE 的包(用户必须已经安装了 Java 才能使用生成的包).

I have a JavaFX 8 desktop application and I'm creating an .app application bundle to distribute the application to Mac users. To keep the size down, I create a bundle that doesn't contain the JRE (the user must have Java already installed to use the generated bundle).

我的构建是一个 Gradle 脚本,但由于 Oracle Self-Contained Application Packaging"工具与 Ant 一起工作,我调用 Ant 脚本如下:

My build is a Gradle script but since the Oracle "Self-Contained Application Packaging" tool works with Ant, I make a call out to an Ant script as follows:

ant.importBuild 'mac-bundle-ant.xml'

Ant 脚本本身如下所示:

The Ant script itself then looks like this:

<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 中发现了以下有问题的行:

The problem is that the generated .app bundle does not work. Looking inside, I've found the following problematic line in Contents/Java/VocabHunter.cfg:

app.runtime=$APPDIR/PlugIns/Java.runtime

如果我去掉这一行,那么 .app 包会按预期工作.现在,我已将以下 hack 添加到我的 Gradle 脚本中以解决该问题:

If I get rid of this line then the .app bundle works as expected. For now I've added the following hack to my Gradle script to work around the problem:

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)
    }
}

您可以在此处查看完整代码.

You can see the full code here.

有谁知道如何修复 Ant 脚本从而避免对 Gradle 文件中的 hack 的需要?

Does anyone know how to fix the Ant script and thus avoid the need for the hack in the Gradle file?

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

In the interests of completeness, I'm using the Oracle JDK 1.8.0_66 for Mac.

推荐答案

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

This bug starts to exist from java 1.8.0 update 60, I already reported this but it's not a official bug yet.

问题是内部打包器现在使用INI-file-format,你可以看到我的发现.

The problem is the internal packager using INI-file-format now, you can see my findings here.

您应该能够将捆绑参数launcher-cfg-format"设置为prop"值(喜欢这里)

You should be able to set the bundle-argument "launcher-cfg-format" with the value "prop" (like here)

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

disclaimer: I'm the maintainer of the javafx-maven-plugin ... and dont use gradle, but this should be added as far as I can see:

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

这篇关于适用于 Mac 的 JavaFX 自包含应用程序打包,无需 JRE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆