Search code examples
javadeploymentantjavafxpackaging

Java Packager Tool : custom install location


I'm working around "Self-Contained Application" generation using Java Packager Tool. By default, the '.exe' bundle is installed under "C:\Program Files (x86)" but I would like install it to a custom location : "C:\MyApp" for example.

To generate my bundle, I'm using an Ant Task inside a Maven build :

<target xmlns:fx="javafx:com.sun.javafx.tools.ant">

    <property name="jre.dir" value="${env.JAVA_HOME}/jre" />
    <property name="version" value="0.0.3" />

    <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
        uri="javafx:com.sun.javafx.tools.ant" classpath="${env.JAVA_HOME}/lib/ant-javafx.jar" />

    <echo message="// ----------------------------------- //" />
    <echo message="//     START JAVAPACKAGER ANT TASK     //" />
    <echo message="// ----------------------------------- //" />

    <fx:deploy nativeBundles="exe" outdir="${basedir}/packager"
        outfile="MyApp_${version}">

        <fx:application name="MyApp" mainClass="com.myfirm.myapp.bootstrap.BootstrapMain">
            <fx:argument>-bundlesDir=./bundles/</fx:argument>
        </fx:application>

        <fx:resources>
            <fx:fileset dir="${project.basedir}/target"
                includes="${project.name}-${project.version}-jar-with-dependencies.jar" />
            <fx:fileset dir="${project.basedir}" includes="bundles/*.jar" />
        </fx:resources>

        <fx:info title="MyApp ${version}" vendor="MyFirm">
            <fx:icon href="${project.basedir}/myapp.ico" kind="default" width="32" height="32" depth="8" />
        </fx:info>

        <fx:preferences install="true" shortcut="true" />

        <fx:platform basedir="${jre.dir}"/>   

    </fx:deploy>
</target>

Has anybody work around this ? And could tell me more about how to configure more precisely the generated native bundle ?

Thanks by advance.

EDIT

Under Windows, I have found a way to do it : by editing file com\oracle\tools\packager\windows\template.iss in jar %JAVA_HOME%\lib\ant-javafx.jar. But this solution seems to be ugly and not portable ! So I'm now looking for a way to override it in my ant task...


Solution

  • For extra documentation, what Tib Us did was edit %JAVA_HOME%\lib\ant-javafx.jar. You can use 7-Zip (or others) to open that jar file and update it's contents.


    In com\oracle\tools\packager\windows\template.iss, change this line:

    DefaultDirName=APPLICATION_INSTALL_ROOT\APPLICATION_NAME
    

    To:

    DefaultDirName={pf}\APPLICATION_NAME
    

    {pf} is a Inno Setup constant pointing to 32-bit or 64-bit Program Files folder. See Inno Setup Help.


    If you'd like to install in Program Files, then it is helpful to change:

    PrivilegesRequired=APPLICATION_INSTALL_PRIVILEGE
    

    To:

    PrivilegesRequired=admin
    

    Also, if your program is going to be used by non-admin users and will be writing to its folder in Program Files, then you'll need some special folder permissions. Here is some background on permissions for an app running in Program Files.


    You might also like to add this, to ensure that the new install location is used:

    UsePreviousAppDir=No
    

    This solution isn't ideal, but is better than nothing.