Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a MSI Windows installer for a Java program?

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.

My current archive contains:

  • a Java Runtime Environment (OpenJDK 1.7 JRE)
  • a script (.bat)
  • a fat JAR
  • an icon file
  • a few text files

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.

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 here. Do I have to use anything else to create a shortcut to uninstall my program?

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.

I know how to add a file, it's explained here 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?

How to pick some unique GUIDs?

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.

Edit.: This is my first wxs file:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="Truly Unusual Experience of Revolution" Language="1033" Version="0.0.0.0" Manufacturer="Julien Gouesse" UpgradeCode="00000000-0000-0000-0000-000000000000">
    <!-- Installer's Icon in Add/Remove Programs -->
	<Icon Id="icon.ico" SourceFile="tuerLogo.ico"/>
    <Property Id="ARPPRODUCTICON" Value="icon.ico" />
	<!-- Installer's version = 200 because the 64-bit support is required -->
    <Package InstallerVersion="200" InstallPrivileges="elevated" InstallScope="perMachine" Compressed="yes" Platform="x64" />
    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
    <MajorUpgrade AllowDowngrades="yes" IgnoreRemoveFailure="yes" Schedule="afterInstallInitialize" />
    <Condition Message="This application is only supported on Windows XP, Windows Vista, Windows Server 2008, or higher.">
      <![CDATA[Installed OR (VersionNT >= 501)]]>
    </Condition>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="APPLICATIONROOTDIRECTORY" Name="Truly Unusual Experience of Revolution">
		  <Component Id="tuer.bat" Guid="00000000-0000-0000-0000-000000000000">
            <File Id="tuer.bat" Source="tuer.bat" KeyPath="yes"/>
		  </Component>
		  <Component Id="tuer.jar" Guid="00000000-0000-0000-0000-000000000000">
            <File Id="tuer.jar" Source="tuer.jar" KeyPath="yes"/>
		  </Component>
		  <Component Id="LICENSE.txt" Guid="00000000-0000-0000-0000-000000000000">
            <File Id="LICENSE.txt" Source="LICENSE.txt" KeyPath="yes"/>
		  </Component>
		  <Component Id="NOTICE.txt" Guid="00000000-0000-0000-0000-000000000000">
            <File Id="NOTICE.txt" Source="NOTICE.txt" KeyPath="yes"/>
		  </Component>
		  <Component Id="README.txt" Guid="00000000-0000-0000-0000-000000000000">
            <File Id="README.txt" Source="README.txt" KeyPath="yes"/>
		  </Component>
		</Directory>
      </Directory>
	  <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="Truly Unusual Experience of Revolution"/>
      </Directory>
	</Directory>
	<!-- Shortcut in the Start Menu -->
	<DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="00000000-0000-0000-0000-000000000000">
        <Shortcut Id="ApplicationStartMenuShortcut" 
                  Name="Truly Unusual Experience of Revolution" 
                  Description="First person shooter"
                  Target="[#tuer.bat]"
                  WorkingDirectory="APPLICATIONROOTDIRECTORY"
			      Icon="icon.ico" />
          <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
          <RegistryValue Root="HKCU" Key="Software\Microsoft\TrulyUnusualExperienceofRevolution" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>
    <Feature Id="TrulyUnusualExperienceofRevolution" Title="Truly Unusual Experience of Revolution" Level="1">
	  <ComponentRef Id="tuer.bat" />
	  <ComponentRef Id="tuer.jar" />
	  <ComponentRef Id="LICENSE.txt" />
	  <ComponentRef Id="NOTICE.txt" />
	  <ComponentRef Id="README.txt" />
	  <ComponentRef Id="ApplicationShortcut" />
	</Feature>
  </Product>
</Wix>

Edit.2: This is the file obtained by running "heat" on the JRE directory.

N.B: I don't answer to my own question but I stopped investigating when I discovered that building an installer with NSIS (Nullsoft Scriptable Install System) would be a lot easier because there are already an Ant task and some packages for several GNU Linux distros (including Mageia, Fedora, ...) to make it work. You can find a script called Java Launcher 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), another script with automatic JRE installation and a rudimentary example of nsi script for a Java based software.

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 Java Native Deployment Toolkit.

like image 391
gouessej Avatar asked Apr 20 '15 12:04

gouessej


People also ask

What is the MSI enterprise JRE installer?

With the release of Java SE 8u20, Oracle introduced an MSI Enterprise JRE Installer. This is a new MSI compatible installer that enables system administrators to install the JRE across the enterprise without end user interaction.

How do I create a Windows Installer package for a Java application?

Let's say that we want to create a Windows Installer package for the included Java Product example. Start Advanced Installer and choose “Java” > “Java Application” as the project type. A good idea is to save and name the project at this point.

How do I run an interactive installation using the Windows MSI?

Instructions for running an interactive installation using the Windows MSI installer: Download the .msi file. Open it to launch the installation program. Read and accept the license if you are happy with the terms.

What is MSI installer and how does it work?

Integrated with the MSI Installer is the Java Uninstall Tool, which provides the option to remove older versions of Java from the system. Now the common features such as rollback of unsuccessful installs, repair of broken installations and installing over existing broken installations are all accessible with the MSI Installer in place.


1 Answers

The javapackager from the OpenJDK project for Java 8/9 includes the ability to package MSI installers (using WIX) that include custom JRE installations for the installed application. If you don't wish to use the packager provided with Oracle Java or one that you compile from the OpenJDK source, maybe reviewing the javapackager source code might help you to create your own packaging utilities.

Licensing seems to be a concern for you - so if you adopt this path, you can check that the OpenJDK legal documents are amenable to your situation. Note that if you use OpenJDK, the Oracle BCL is not applicable.

I have not checked the javapackager source in detail, but it may have some reliance on Java 8 features. As your target is to create a JRE 7 based package, you might be able to use a Java 8 runtime to execute the packager, but package a Java 7 JRE as a target. If you must run the packaging tools using a Java 7 runtime and the packager code uses Java 8 features - you could fork it and backport it to Java 7 (you would need some pretty strict requirements to require this - most people would not have such requirements).

I'm not recommending the above as the most ideal way to accomplish your task - I'm just throwing out some ideas which might or might not be useful to you.

like image 198
jewelsea Avatar answered Sep 24 '22 17:09

jewelsea