title: How to create a MSI Windows installer for a Java program?
body: <p>I'd like to create a single Microsoft Installer file for a Java program. I can't use Netbeans or any Maven plugin to do it because I can't use Oracle Java and/or JavaFX (mainly for legal reasons) and both seem to use Oracle native deployment + JavaSE 1.8.</p>
  
  <p><a href="http://sourceforge.net/projects/tuer/files/tuer/tuer-0.0.0/tuer-0.0.0-0.windows.amd64.zip/download" rel="nofollow noreferrer">My current archive</a> contains:</p>
  
  <ul>
  <li>a Java Runtime Environment (OpenJDK 1.7 JRE)</li>
  <li>a script (.bat)</li>
  <li>a fat JAR</li>
  <li>an icon file</li>
  <li>a few text files</li>
  </ul>
  
  <p>I don't want to use the JRE of the system, that's why I provide another JRE. The script just calls the JRE with a few arguments. The icon file is in .ico format. The fat JAR is the JAR containing all necessary Java classes, native libraries and assets, including the third party libraries.</p>
  
  <p>I'd like to allow the end user to install, run and uninstall my program. I want to provide one shortcut in the start menu to run it and another one to uninstall it. It seems to be explained <a href="http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_start_menu_shortcut.html" rel="nofollow noreferrer">here</a>. Do I have to use anything else to create a shortcut to uninstall my program?</p>
  
  <p>I've looked at Wix Toolset for several weeks. I understand that I have to write a wxs file to use with "candle.exe", it creates a wixobj file, I have to run "light.exe" with this file and I get a MSI file.</p>
  
  <p>I know how to add a file, it's explained <a href="http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/add_a_file.html" rel="nofollow noreferrer">here</a> but I don't know how to add the whole directory containing the JRE without mentioning each file one by one. How can it be done in the wxs file?</p>
  
  <p>How to pick some unique GUIDs?</p>
  
  <p>Is there already a (more?) simple tool that I can use to make a MSI file from a fat JAR? I prefer understanding how to build such a file in command line under Windows first before trying to do the same programmatically with Apache POI under GNU Linux.</p>
  
  <p>Edit.: This is my first wxs file:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"&gt;
    &lt;Product Id="*" Name="Truly Unusual Experience of Revolution" Language="1033" Version="0.0.0.0" Manufacturer="Julien Gouesse" UpgradeCode="00000000-0000-0000-0000-000000000000"&gt;
      &lt;!-- Installer's Icon in Add/Remove Programs --&gt;
   &lt;Icon Id="icon.ico" SourceFile="tuerLogo.ico"/&gt;
      &lt;Property Id="ARPPRODUCTICON" Value="icon.ico" /&gt;
   &lt;!-- Installer's version = 200 because the 64-bit support is required --&gt;
      &lt;Package InstallerVersion="200" InstallPrivileges="elevated" InstallScope="perMachine" Compressed="yes" Platform="x64" /&gt;
      &lt;Media Id="1" Cabinet="media1.cab" EmbedCab="yes" /&gt;
      &lt;MajorUpgrade AllowDowngrades="yes" IgnoreRemoveFailure="yes" Schedule="afterInstallInitialize" /&gt;
      &lt;Condition Message="This application is only supported on Windows XP, Windows Vista, Windows Server 2008, or higher."&gt;
        &lt;![CDATA[Installed OR (VersionNT &gt;= 501)]]&gt;
      &lt;/Condition&gt;
      &lt;Directory Id="TARGETDIR" Name="SourceDir"&gt;
        &lt;Directory Id="ProgramFilesFolder"&gt;
          &lt;Directory Id="APPLICATIONROOTDIRECTORY" Name="Truly Unusual Experience of Revolution"&gt;
      &lt;Component Id="tuer.bat" Guid="00000000-0000-0000-0000-000000000000"&gt;
              &lt;File Id="tuer.bat" Source="tuer.bat" KeyPath="yes"/&gt;
      &lt;/Component&gt;
      &lt;Component Id="tuer.jar" Guid="00000000-0000-0000-0000-000000000000"&gt;
              &lt;File Id="tuer.jar" Source="tuer.jar" KeyPath="yes"/&gt;
      &lt;/Component&gt;
      &lt;Component Id="LICENSE.txt" Guid="00000000-0000-0000-0000-000000000000"&gt;
              &lt;File Id="LICENSE.txt" Source="LICENSE.txt" KeyPath="yes"/&gt;
      &lt;/Component&gt;
      &lt;Component Id="NOTICE.txt" Guid="00000000-0000-0000-0000-000000000000"&gt;
              &lt;File Id="NOTICE.txt" Source="NOTICE.txt" KeyPath="yes"/&gt;
      &lt;/Component&gt;
      &lt;Component Id="README.txt" Guid="00000000-0000-0000-0000-000000000000"&gt;
              &lt;File Id="README.txt" Source="README.txt" KeyPath="yes"/&gt;
      &lt;/Component&gt;
    &lt;/Directory&gt;
        &lt;/Directory&gt;
     &lt;Directory Id="ProgramMenuFolder"&gt;
          &lt;Directory Id="ApplicationProgramsFolder" Name="Truly Unusual Experience of Revolution"/&gt;
        &lt;/Directory&gt;
   &lt;/Directory&gt;
   &lt;!-- Shortcut in the Start Menu --&gt;
   &lt;DirectoryRef Id="ApplicationProgramsFolder"&gt;
        &lt;Component Id="ApplicationShortcut" Guid="00000000-0000-0000-0000-000000000000"&gt;
          &lt;Shortcut Id="ApplicationStartMenuShortcut" 
                    Name="Truly Unusual Experience of Revolution" 
                    Description="First person shooter"
                    Target="[#tuer.bat]"
                    WorkingDirectory="APPLICATIONROOTDIRECTORY"
           Icon="icon.ico" /&gt;
            &lt;RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/&gt;
            &lt;RegistryValue Root="HKCU" Key="Software\Microsoft\TrulyUnusualExperienceofRevolution" Name="installed" Type="integer" Value="1" KeyPath="yes"/&gt;
        &lt;/Component&gt;
      &lt;/DirectoryRef&gt;
      &lt;Feature Id="TrulyUnusualExperienceofRevolution" Title="Truly Unusual Experience of Revolution" Level="1"&gt;
     &lt;ComponentRef Id="tuer.bat" /&gt;
     &lt;ComponentRef Id="tuer.jar" /&gt;
     &lt;ComponentRef Id="LICENSE.txt" /&gt;
     &lt;ComponentRef Id="NOTICE.txt" /&gt;
     &lt;ComponentRef Id="README.txt" /&gt;
     &lt;ComponentRef Id="ApplicationShortcut" /&gt;
   &lt;/Feature&gt;
    &lt;/Product&gt;
  &lt;/Wix&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Edit.2: <a href="http://gist.github.com/gouessej/6fbc9a7ca286cba7fb34" rel="nofollow noreferrer">This</a> is the file obtained by running "heat" on the JRE directory.</p>
  
  <p><strong>N.B:</strong> I don't answer to my own question but I stopped investigating when I discovered that building an installer with NSIS (<a href="http://nsis.sourceforge.net" rel="nofollow noreferrer">Nullsoft Scriptable Install System</a>) would be a lot easier because there are already <a href="https://sourceforge.net/projects/nsis-ant/" rel="nofollow noreferrer">an Ant task</a> and some packages for several GNU Linux distros (including <a href="https://pkgs.org/mageia-5/mageia-core-release-x86_64/mingw32-nsis-2.46-13.mga5.x86_64.rpm.html" rel="nofollow noreferrer">Mageia</a>, Fedora, ...) to make it work. You can find a script called <a href="http://nsis.sourceforge.net/Java_Launcher" rel="nofollow noreferrer">Java Launcher</a> to look for a JRE in your software and in your operating system (even though I advise you to bundle an OpenJDK JRE in your software to ensure that it will go on working despite the updates or the absence of a JRE in the operating system), <a href="http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation" rel="nofollow noreferrer">another script with automatic JRE installation</a> and <a href="https://www.seas.gwu.edu/~simhaweb/java/lectures/appendix/installer/install.html" rel="nofollow noreferrer">a rudimentary example of nsi script for a Java based software</a>.</p>
  
  <p>P.S: By the way, I now use my own tool (which uses Redline RPM under the hood), it's fully documented, open source (under GPL), and works for RPM, DEB, APP and EXE (via NSIS) too, it's called <a href="http://tuer.sourceforge.net/en/documentation/#jndt" rel="nofollow noreferrer">Java Native Deployment Toolkit</a>.</p>