4

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

thibault
  • 379
  • 1
  • 3
  • 13
  • The installers installation directory depends on INNO/WIX setup for Windows. – ItachiUchiha Mar 31 '15 at 17:05
  • @ItachiUchiha Yes I know about INNO/WIX, but none of them allow to specify custom installers installation directory as I can see [here](https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html), Table 7-2 – thibault Mar 31 '15 at 19:19
  • You may want to go through [WIX Documentation for custom path](http://wixtoolset.org/documentation/manual/v3/wixui/dialog_reference/wixui_installdir.html). If you are using Inno, it has a similar feature. – ItachiUchiha Mar 31 '15 at 19:39
  • @ItachiUchiha Ok, but where can I override it from my build script ?? – thibault Apr 01 '15 at 07:41
  • You can't you need to write your own script and execute it while using the custom packager in your build file. – ItachiUchiha Apr 01 '15 at 09:10
  • I see, but doing that I loose the portability of my script... – thibault Apr 01 '15 at 11:30
  • To overcome the scenario, you could package the Wix/Inno along with the project. – ItachiUchiha Apr 01 '15 at 11:47
  • To @thibault, and any other passers-by, you *dont* have to edit the JDK. Simply take the template and use it as a drop-in resource. The javapackager will still inject your version number and all that. See [my answer](https://stackoverflow.com/a/54027883/5432315) for full details. – Brad Turek Jan 03 '19 at 18:42

3 Answers3

3

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.

Community
  • 1
  • 1
Jon Onstott
  • 13,499
  • 16
  • 80
  • 133
  • Editing the JDK isn't necessary to accomplish your goal. Just take that [template file](https://gist.github.com/TurekBot/8aa610bcd6695a6b5e7722bd4111a7f5) and use it as a [drop-in resource](https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html#BCGICFDB). The javapackager will still replace all the UPPER_WITH_UNDERSCORE variables. – Brad Turek Jan 03 '19 at 18:34
2

Getting the template from the jar file is fine—or download it here—but you don't need to edit it where it is.

Once you have that template, you can just use it as a drop-in resource. All the variables that look like SOME_VARIABLE, that is, upper case and which use underscores, will still be replaced by the javapackager.

This solution is much more portable because it doesn't involve editing the JDK; just include your template in package/windows/ as YourAppName.iss.

Brad Turek
  • 2,472
  • 3
  • 30
  • 56
  • 4 years later, this comment was a saviour. To add, the following additions to the Java 9 docs added the extra step I need to work in a modular system. https://bugs.openjdk.org/browse/JDK-8186683?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel – Graham Meehan Nov 04 '22 at 23:17
-1

User Option -BinstalldirChooser=true

Ashish
  • 11
  • 1