Saturday, September 10, 2011

Deploying a JAVA application with Wix Tool Set

As I was trying to build a installer for java application using Wix that could detect JRE Installation and install only if JRE was present. I stumbled across a number of forums and blogs.Finally I found a good solution. The key steps involved were 
 1.Setting the working directory for a java application in the start menu shortcut properties
 2. Check the registry for existence of specific JRE versions .

The highlighted Grey text in the mark up shown below emphasises the same

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="">
      <Product Id="07f0003f-4290-4f4c-9442-c2d203f64b4f" Name="TestJar " Language="1033" Version="" Manufacturer="abc" UpgradeCode="00e83a73-37c7-4ec0-88f4-9612dcb05a0d">
            <Package InstallerVersion="200" Compressed="yes" />
            <Media Id="1" Cabinet="" EmbedCab="yes" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder"  Name="ProgramFilesFolder">
        <Directory Id="INSTALLLOCATION" Name="TestJar">
          <Component Id="component1" Guid="323CBA27-E825-4b15-B297-ABBEA9B686DA">
            <File Id='Test.jar' Name='Test.jar'  DiskId='1'                                      Source="E:\JavaProj\Bin\Test.jar" Vital='yes'/>
            <File Id='Start.bat' Name='Start.bat'  DiskId='1'
                   Source="E:\JavaProj\Bin\Start.bat" Vital='yes'/>
      <Directory Id="StartMenuFolder" >
        <Directory Id ="ProgramMenuFolder">
          <Directory Id="TestJar" Name ="TestJar">
            <Component Id ="component3" Guid ="92B0EDF4-664E-4707-AD32-066DD3993A57"  >
              <Registry Root="HKCU" Key ="Software\[Manufacturer]\[ProductName]" Value ="[INSTALLLOCATION]" Type ="string" KeyPath ="yes" />
              <Shortcut Id="MyTestShortCutA"  Directory ="TestJar "  Name="testjar "   Icon ="icon1" Show="normal" WorkingDirectory="INSTALLLOCATION"  Target ="[!start.bat]">

            <Icon Id="icon1" SourceFile="E:\JavaProj\Bin\images\User1.ico" />
            </Component >
          </Directory >
    </Directory >
    </Directory >
        <Property Id="JAVA_CURRENT_VERSION">
      <RegistrySearch Id="JRE_KEY" Root="HKLM" Key="SOFTWARE\JavaSoft\Java Runtime Environment" Name="EVersion" Type="raw"  />
    <Condition Message="Java not installed  Please install JRE 1.6 or later."><![CDATA[(Installed OR JAVA_CURRENT_VERSION) AND JAVA_CURRENT_VERSION >= "1.6"]]></Condition>      
    <Feature Id='Complete' Level='1' ConfigurableDirectory ='INSTALLLOCATION'>
      <ComponentRef Id='component1' />
      <ComponentRef Id='component3' />
    </Feature >
     <Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION" ></Property>
    <WixVariable Id="WixUIBannerBmp" Value="E:\JavaProj\Bin\images\Test.bmp" />
    <WixVariable Id="WixUIDialogBmp" Value="E:\JavaProj\Bin\images\blank.bmp" />
    <UIRef Id="WixUI_InstallDir" /> 

Note:Registry search keys may change depending on different JRE Versions.