How can I create installer for java application?

Answered

Comments

3 comments

  • Avatar
    juanjo

    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:

    <autodetectJava>
      <abortOnError>0</abortOnError>
      <promptUser>0</promptUser>
      <showMessageOnError>0</showMessageOnError>
    </autodetectJava>
    <throwError text="Java is required but was not found.
      Please install it an relaunch this installer">
      <ruleList>
        <isFalse>
          <value>${java_autodetected}</value>
        </isFalse>
      </ruleList>
    </throwError>
    

    You could even download it at runtime:

     <actionGroup>
             <actionList>
                <showProgressDialog>
                  <title>Downloading files</title>
                  <actionList>
                    <httpGet>
                      <filename>${installdir}/java.tar.gz</filename>
                      <url>http://www.example.com/downloads/java/1.6/jre1.6.0_24-linux.tar.gz</url>
                    </httpGet>
                  </actionList>
                </showProgressDialog>
                <runProgram>
                  <program>tar</program>
                  <programArguments>xzf ${installdir}/java.tar.gz -C ${installdir}</programArguments>
                </runProgram>
             </actionList>
             <ruleList>
                <isFalse>
                   <value>${java_autodetected}</value>
                </isFalse>
             </ruleList>
          </actionGroup>
    

    You could also create a luncher for your jar file:

      <createJavaLaunchers>
        <destination>${installdir}/javalaunchers</destination>
        <javaLauncherList>
          <javaLauncher>
            <binaryName>launcher1</binaryName>
            <classpath>testapplication.jar;additional.jar</classpath>
            <mainClass>com.bitrock.testapplication.MainClass</mainClass>
            ...
            <windowsResourceFileVersion>1.0.0.0</windowsResourceFileVersion>
            <windowsResourceLegalCopyright>Test Launcher 1</windowsResourceLegalCopyright>
            <windowsResourceLegalTrademarks>(c) 2010 Bitrock S.L.</windowsResourceLegalTrademarks>
            <windowsResourceOriginalFilename>launcher1.exe</windowsResourceOriginalFilename>
            <windowsResourceProductName>Test launcher 1</windowsResourceProductName>
            <windowsResourceProductVersion>1.0</windowsResourceProductVersion>
            <workingDirectory>${installdir}/javalaunchers</workingDirectory>
          </javaLauncher>
       </javaLauncherList>
      </createJavaLaunchers>
    

    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

    <createShortcuts>
        <destination>${windows_folder_startup}/</destination>
        <shortcutList>
            <shortcut>
                <comment>Client for managing myapp</comment>
                <name>Launch myapp client</name>
                <runAsAdmin>1</runAsAdmin>
                <windowsExec>${installdir}/javalaunchers/launcher1.exe</windowsExec>
                <windowsExecArgs>--dock</windowsExecArgs>
                <windowsPath>${installdir}</windowsPath>
            </shortcut>
        </shortcutList>
    </createShortcuts>
    
  • Avatar
    Rust

    Just use actual installer that sripting tool. http://www.actualinstaller.com

  • Avatar
    tahoar

    InstallBuilder's Java support page gives you a really good start. http://installbuilder.bitrock.com/java/

    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.