How can I create installer for java application?




  • Avatar

    If your application is a Java jar file, you could either require the Java runtime to be installed in the target machine or bundle it within your installer.

    You could also try to autodetect it using the <autodetectJava> action, and if you cannot find any valid version, either unpack a bundled one or throw an error:

    <throwError text="Java is required but was not found.
      Please install it an relaunch this installer">

    You could even download it at runtime:

                  <title>Downloading files</title>
                  <programArguments>xzf ${installdir}/java.tar.gz -C ${installdir}</programArguments>

    You could also create a luncher for your jar file:

            <windowsResourceLegalCopyright>Test Launcher 1</windowsResourceLegalCopyright>
            <windowsResourceLegalTrademarks>(c) 2010 Bitrock S.L.</windowsResourceLegalTrademarks>
            <windowsResourceProductName>Test launcher 1</windowsResourceProductName>

    You can find additional information in our online documentation.

    Regarding starting the application at startup, if you create a launcher you could just create a shortcut to the startup menu

                <comment>Client for managing myapp</comment>
                <name>Launch myapp client</name>
  • Avatar

    Just use actual installer that sripting tool.

  • Avatar

    InstallBuilder's Java support page gives you a really good start.

    The link includes different compressed Java packages for various platforms. Just expand them; then put all of the subfolders in one place. I use these:

    • installbuilder-8.2.0/jre1.7.0_04/java-linux
    • installbuilder-8.2.0/jre1.7.0_04/java-linux-64
    • installbuilder-8.2.0/jre1.7.0_04/java-windows

    Each compressed package has its own java.xml. The only difference between the different java.xml files is the value of a variable called "java_bitness", where it's different for 32 vs 64 bit platforms:

    <setInstallerVariable name="java_bitness" value="32" />
    <setInstallerVariable name="java_bitness" value="64" />

    So, I consolidated them into one by making two changes. Now, I can use only one java.xml in my installer package. The changes include:

    1. Change existing value to refer to a variable:

      <setInstallerVariable name="java_bitness" value="${host_bitness}" />

    2. Create a new action list that sets the new ${host_bitness} variable:

      <initializationActionList> <setInstallerVariable> <name>host_bitness</name> <value>32</value> </setInstallerVariable> <setInstallerVariable> <name>host_bitness</name> <value>64</value> <ruleList> <platformTest> <type>linux-x64</type> </platformTest> </ruleList> </setInstallerVariable> <setInstallerVariable> <name>host_bitness</name> <value>64</value> <ruleList> <platformTest> <type>windows-x64</type> </platformTest> </ruleList> </setInstallerVariable> <setInstallerVariableFromScriptOutput> <exec>isainfo</exec> <execArgs>-v</execArgs> <name>solaris_bitness</name> <ruleList> <platformTest> <type>solaris</type> </platformTest> </ruleList> </setInstallerVariableFromScriptOutput> <setInstallerVariable> <name>host_bitness</name> <value>64</value> <ruleList> <compareText> <logic>contains</logic> <nocase>1</nocase> <text>${solaris_bitness}</text> <value>64</value> </compareText> </ruleList> </setInstallerVariable> </initializationActionList>

    I would suggest the InstallBuilder team incorporate these changes to next program update.

    Finally, this java.xml component does not detect existing Java installations. So, I have another java-detect.xml component that uses <autodetectJava> and installs the new package only if Java is not detected on the host. This component also detects if the host is a Debian Linux distribution and if the users is running as superuser. It then uses apt-get to install java, no the packages here. This could be expanded to include yum for Redhat/Fedora, and other package managers for other distros. If anyone is interested in this component, I'll be happy to share it somewhere.

Please sign in to leave a comment.