Reputation: 4125
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:
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.
Upvotes: 7
Views: 21448
Reputation: 647
Upgrade to Java 14+ and use the built-in jpackage tool (which is the descendant of the 'jpackager' from Jave 8/9). Like most, it generates packages for the system you run it on:
It uses jdeps and jlink to build a minimal JRE to include in the installer, avoiding the need to separately download Java. Plus, it's free with every JDK download. Thanks to Kevin Rushforth and the JEP343 team! Read the development log at https://bugs.openjdk.java.net/browse/JDK-8200758 or do jpackage --help. Note that, as of Java14, it's technically still in "incubation" so some features might change.
Upvotes: 6
Reputation: 2253
Just stumbled upon this question. Maybe my two cents can help. I use two maven plugins together:
1) launch4j-maven-plugin (com.akathist.maven.plugins.launch4j) used to wrap the jar inside an exe file. It also allows to specify a minimum java version. That way, you don't have to ship the java version with the msi (which then has to be updated from time to time), but just redirect the user to the java download page (lightweight solution). Launch4J has a bunch of other features, which makes your java application look nicer f.i. a SplashScreen or you can pass startup params, which is nice. That way you can build very custom installers just by setting some properties in the pom.xml
2) wix-maven-plugin (org.bitbucket.joxley) Since we have an exe now we can create a very nice installer, with desktop shortcuts and a "launch now" checkbox at the end of the installation process.
This combination is not the easiest one to implement, but once it is in place you have countless options to build different versions of your software (Evaluation Copy/Pro Version) and to customize your software (e.g. different look and feel of the installer, even attaching a different software licence is possible). With the command line arguments set in the launch4J plugin you can create an app which starts in a certain state or with a certain configuration.
We use the solution in production for several years now.
Upvotes: 2
Reputation: 159566
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.
Upvotes: 3
Reputation: 55600
I run an opensource project called IsWiX that handles this scenario. You can watch a video (linked below) for creating an MSI for a WPF .NET desktop application.
The concepts are the same for a Java application. You just deploy a private instance of the JRE along with your application and create a shortcut that points to the .BAT file. About the only thing you would do custom is create an Icon element that points to your ICO file and set an attribute on the Shortcut element to point to the icon. In the compiled code world we don't have to do this as the shortcut will automatically display the default icon resource in the target executable.
A little write up on the video can be found here:
Building and Deploying a Windows Desktop Application using IsWiX
And the (silent) video itself:
Building and Deploying a Windows Desktop Application using IsWiX
Upvotes: 1