5

I imagine some Java gurus with experience delivering Java apps on Windows desktops will be able to ace this one. I've always been a Mac/Linux Java developer so this is uncharted territory for me :-/.

I have to write a Java 8 Swing application and install it on a Windows 10 (64-bit) machine. My gameplan is to package the app as an executable JAR and wrap it with Launch4J, so that it looks like a native Windows EXE (.exe file). However its a little bit more complication than that when it comes to the distribution:

  • There will be the JAR/EXE as mentioned above, lets call it myapp.exe (built from myapp.jar)
  • The app will output logs to a (local?) directory, myapp.log
  • The app will load a config file at runtime, myapp.properties
  • The distribution should also contain the User's Guide, MyApp User Guide.html

Let's assume a Java 8 JRE/JDK is already installed on the machine, so we don't need to worry about installing Java itself.

The installation process must be simple and include:

  1. Removing the old version (and all of its other artifacts such as the log file, config/properties file, user guide, etc) off the machine completely
  2. Installing the new version at either the Windows 10 default location, or allowing the user to specify a different location

Additionally, if at all possible, I'd like the installation process to include:

  1. A requirements check for things like minimum memory and disk space, OS version info/compatibility (i.e. make sure its being installed on Windows 10, etc.)
  2. Provide an easy-to-use wizard such as an MSI that the user can click though
  3. Optionally install shortcuts to the user's Desktop

Given all this, I'm wondering what my options are in the modern Windows 10/Java/Launch4J landscape. Are there tools that will help me script together MSIs quickly, or do I have to write my own in, say, C#/.NET and have that be a separate binary/project? If MSIs aren't an option, what options exist that might hit all my bullets above?

I realize I could just distribute the whole thing as a ZIP, and have the installation process look something like:

  1. Save the ZIP to some place on the user's machine, say, the Desktop
  2. Move the previous app and its artifacts to the trash, manually
  3. Unzip the new ZIP

However that feels janky and I'm looking for something more professional. Any solutions here?

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
hotmeatballsoup
  • 385
  • 6
  • 58
  • 136
  • Why the CV? Its on topic, is not a dupe, is an [SSCCE](http://sscce.org) and is valuable information to any modern Java/Windows developers. – hotmeatballsoup Nov 14 '19 at 19:16
  • I don't do a lot of multi-platform work. Sending you a couple of links at least: [Multi-Platform Installers](https://stackoverflow.com/questions/51619358/does-an-universal-cross-platform-installer-exists/51624645#51624645). And a list of [the major MSI installer tools](https://stackoverflow.com/a/50229840/129130). – Stein Åsmul Nov 16 '19 at 19:53
  • Downvoted. 1) Tool recommendation is off-topic. 2) Defining "more professional" is subjective and opinion based, so again off-topic. 3) Like the other commented, tons of tools can be found from a search engine, commercial or free. They might be Java specific or generic for Windows, and both should work. – Lex Li Nov 16 '19 at 20:33
  • I don't see this as tool recommendation, more approach recommendation, which is an aspect of all software design & architecture. And I'm expecting that there are known solutions to this particular problem set, which would be more productionalized than what I've identified above, that's all I meant by "professional". – hotmeatballsoup Nov 16 '19 at 21:20
  • Please see the links provided above. Frankly Java deployment has always been a bit confusing. Many weird solutions at times. Commercial tools Advanced Installer and Installshield have some features for Java. WiX can also do what you list since the list is essentially standard MSI features (which these tools compile as output - and some of them can output non-standard EXE files). – Stein Åsmul Nov 16 '19 at 23:00

2 Answers2

6

JDK 8 is bundled with a tool called javapackager (formerly javafxpackager) which is part of JavaFX. However, you can use it package java swing application without using JavaFX. This tool can generate an installer file (exe or msi) which contains the application and the Java runtime as well.

Here is an example:

javapackager -deploy -native exe -Bruntime="C:\Program Files\Java\jdk1.8.0_66\jre" -Bicon=app_icon.ico -BsystemWide=true -BshortcutHint=true -outdir packages -outfile appFile -srcdir dist -srcfiles MyApp.jar;COPYING.txt -appclass somePackage.MainClass -BlicenseFile=COPYING.txt -name appName -title "The application name"

For more information, see adding icon to bundle using javapackager


There is also a new tool called jpackage which is based on javapackager. It is proposed to be released with the next JDK release, JDK 14. Note that javapackager was removed from JDK since version 11 as part of the removal of JavaFX.

See A Brief Example Using the Early Access jpackage Utility

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
  • Thanks @Eng.Fouad (+1) -- Ideally I would like to use Launch4J to build a Windows native EXE for me, and then use a different tool (such as this `javapackager`) to build a Windows MSI for me, separately. Do you know if this is possible to do? Thanks again! – hotmeatballsoup Nov 17 '19 at 13:57
  • 1
    @hotmeatballsoup `javapackager` produces an installer file, which is capable to install the application in program files folder, create desktop shortcut, and also add a record in "Programs and Features" so that the user can uninstall it. The desktop shortcut will point to an exe file that starts the application. – Eng.Fouad Nov 18 '19 at 02:00
  • Thanks again @Eng.Fouad (+1 again) just a few more followup questions for you if that's ok: **(1)** just to **confirm** (for the bounty!): I _should_ be able to build the EXE with Launch4J (or any other tool) and then use `javapackager` for building the MSI, **correct?** – hotmeatballsoup Nov 18 '19 at 11:27
  • Also **(2)** do I have to be on a Windows machine in order to use `javapackager` to build the Windows MSI? Or could I run `javapackager` on, say, Mac/Linux, build the MSI there, and then run the MSI on a different Windows machine? – hotmeatballsoup Nov 18 '19 at 11:29
  • 1
    @hotmeatballsoup No need for `Launch4J` as `javapackager` already produces exe for you. You need to run the tool on Windows in order to produce msi/exe installer file. If you need to produces Mac installer then you need to run the tool on Mac, and so on. – Eng.Fouad Nov 18 '19 at 11:40
  • Thanks, but is it *possible* to build the EXE with Launch4J and then use `javapackager` to build the MSI? I realize I don't *have* to do this, I'm wondering if its possible to do this? – hotmeatballsoup Nov 18 '19 at 11:44
  • AFAIK, it is not possible, as `javapackager` uses jar files as source. – Eng.Fouad Nov 18 '19 at 11:53
  • Last question (I promise!): with `javapackager`, would I need to install a JDK/JRE on my target machines, or does the packager bundle the JRE and my JAR together inside the EXE? – hotmeatballsoup Nov 18 '19 at 11:56
  • 1
    No need to install JRE on the target machine, as it is bundled with the installer file and will be installed with the application jar on the client machine. – Eng.Fouad Nov 18 '19 at 12:07
0

Tools: Some deployment tools information:


Advanced Installer: As stated in a comment above you can use Advanced Installer to install Java applications on Windows and Mac (no Linux support).

Videos: Here are some videos from Advanced Installer (commercial tool) on Java installations:

Tutorial (to read): Package your Java application for Windows and for Mac OS. Java landing page.


Digression: Not Java as such - do have a skim. Auto-updating applications using various deployment technologies: What is the best practice to auto upgrade MSI based application?


Links:

Old: How can I convert my Java program to an .exe file?

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164