Adam
Adam

Reputation: 712

JavaFX Self-Contained Application Packaging for Mac without JRE

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

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'

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>

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

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.

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

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

Upvotes: 0

Views: 678

Answers (1)

FibreFoX
FibreFoX

Reputation: 2858

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

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

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

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"/>

Upvotes: 2

Related Questions