Question

Q: Can the installer autodetect if there is an existing Java(tm) installation in the system?

Can the installer autodetect if there is an existing Java(tm) installation in the system?

Answer:

Yes, you can make the installer autodetect whether or not there is an existing Java(tm) installation in the system by using an <autodetectJava> action. If a suitable Java(tm) is found, the action will also create a number of variables, described later on. This action is usually placed at the <preInstallationActionList> and if no valid JRE or JDK is found, the installer will abort with an error listing the supported JREs and JDKs. The following example will select any Sun Microsystems JRE 1.3 or newer (for example, 1.3, 1.4, 1.5) or any IBM JRE with version number equal or greater than 1.4.2 but inside the 1.4 series (1.5 will not work at this time).

       <autodetectJava>
                 <validVersionList>
                   <validVersion>
                     <vendor>sun</vendor>
                     <minVersion>1.4.2</minVersion>
                     <maxVersion>1.4</maxVersion>
                   </validVersion>
                   <validVersion>
                     <vendor>ibm</vendor>
                     <minVersion>1.3</minVersion>
                     <maxVersion></maxVersion>
                   </validVersion>
                 </validVersionList>
               </autodetectJava>
        

Each element in the <validVersionList> contains the following fields:

  • vendor: sun (to allow only Sun Microsystems JREs,) ibm (to allow only IBM JREs) or empty (to allow any JRE.)
  • minVersion:Minimum supported version of the JRE. Leave empty to not require a minimum version.
  • maxVersion: Maximum supported version of the JRE. Leave empty to not require a maximum version. If specified only with major and minimum version numbers then it will match any number in the series. For example, 1.4 will match any 1.4.x version (1.4.1, 1.4.2, ...) but not a 1.5 series JRE.
  • requireJDK: Whether to require that the Java(tm) installation needs to be a JDK. By default, it is set to 0 so either a JDK or JRE will work.

Upon successful autodetection, the following installer variables will be created :

${java_executable}: Path to the java(tm) command line binary (java.exe in Windows). For example /usr/bin/java, C:\Program Files\Java\j2re1.4.2_03\java.exe.
${java_version}: For example, 1.4.2_03
${java_version_major}: For example, 1.4
${java_vendor}: sun or ibm.