I am working on a simple desktop java application. I would like to make it as seamless to install for end users as possible. E.g. similar to how Minecraft is distributed - a simple executable for OS X and an EXE file for Windows.
What tool should I use?
We will show a few different approaches for deploying an application, so that users can access the application by: Double-clicking the application's Java Archive (JAR) file. Calling the application from the command line. Calling the application from a script file.
Java is used to build robust and platform independent applications in many domains. This language is used for developing Android applications, web applications, desktop applications and many more.
To create a package, you choose a name for the package (naming conventions are discussed in the next section) and put a package statement with that name at the top of every source file that contains the types (classes, interfaces, enumerations, and annotation types) that you want to include in the package.
The Java Packager tool can be used to compile, package, sign, and deploy Java and JavaFX applications from the command line. It can be used as an alternative to an Ant task or building the applications in an IDE. FXLauncher is both a launcher and an auto-updater that focuses solely on JavaFX applications.
Users of your Java app must have the JRE installed in order to run it.
You can either tell them to install Java first, or distribute JRE with your app, as Processing does.
Note, however, that your packaged program will be heavy if you include JRE with it. And, if you want to do that, users will need to download the appropiate package for their platform.
They take your Java app as input and wrap them in an executable (for a specified platform). You can customize them as you like; and if the user doesn't have Java installed, the download page will open.
Some examples are Launch4J, JSmooth and Jar2EXE.
They are independent applications configured to copy your app files to the user's computer and (optionally) create a shortcut.
Some installers are written in Java, so they're multiplatform. In this case, the installer is a .jar
.
Some others are platform-dependent, but you have the advantage that you don't need to wrap them.
Java installers: IzPack, Packlet, PackJacket, Antigen, …
It's a Java feature that allows you users to easily run your apps. You give them a .jnpl
file,
they open it, and Java downloads the latest version of your app and runs it. No packaging troubles!
See the complete list of resources here.
The modern solution to deploying a Java-based desktop app is to bundle a JVM with your app, delivered to the user as a double-clickable package just like other "normal" apps. Think of the JVM as another dependency to be incorporated within your final app.
Learn about:
You could ship a JavaFX (OpenJFX) app this way, as well as a Swing app (the predecessor to JavaFX).
One advantage of this approach is that you know exactly what JVM is being used to run your particular app. Of course it also means you must release a new version of your app when a JVM update contains a relevant fix. Your users no longer are concerned with downloading, installing, and upgrading a JVM, as that chore is now the responsibility of the developer.
One disadvantage of this approach is that you must build, test, and distribute separate binaries of your app, one for each platform (macOS, MS Windows, BSD, Linux, and so on).
See also my Answer on a related Question, How to use jdk without jre in Java 11.
See the Answer by Will Iverson for what looks like some useful tooling.
A cutting-edge variation of this approach is to build an ahead-of-time-compiled (versus JIT) native-code version of your app using GraalVM and its native image generator.
Possibly related: Oracle's Project Leyden. See initial announcement by Mark Reinhold, and see this article, 2020-05-07.
Some other Answers discuss Java Web Start. Be aware that Java Web Start and Java Applets technologies are both being phased out by Oracle. See their white paper, Java Client Roadmap Update dated 2020-05-11.
A possible alternative is the open-source implementation of Java Web Start known as the OpenWebStart project.
Java Web Start I think is the option you're looking for...
Edit
Comment from Basil Bourque @ 2020:
Java Web Start is being phased out by Oracle. See their white paper, Java Client Roadmap Update dated 2020-05-11. You may be interested in the open-source implementation of Java Web Start known as the OpenWebStart project.
Edit: The Java Plug-In, required for both applets and Java Web Start, was deprecated in Java 9 and removed from browsers around the same time. So this answer is obsolete. Only leaving it here to warn people against following this path.
The optimal installation for a cross-platform app. with a GUI is to be found in Java Web Start. To quote the linked document in part:
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update ..
..an OS specific way of launching the software.
Adding a shortcut (with icon) to the desktop or start/program menu (desktop integration) is about as platform specific as you can get.
..will run without Java and offer to install a JRE if not currently present
Use deployJava.js
, linked in the 2nd last list item under 'See also:'.
Well you don't need a separate package per OS if JWS integrates in and looks like a native program.
Using the native PLAF would be a good start.
If you are using Java 16, jlink and jpackage will do what you need - build a desktop application and installer.
Here is a GitHub template that uses Maven to build a small / reduced JVM + JavaFX application. It uses Java modules and jlink to produce the small JVM, but uses the normal class path for running your application. GitHub Actions are used to produce the installers for macOS, Windows, and Linux.
https://github.com/wiverson/maven-jpackage-template
Here is another (WIP) version of the template with a small Swing UI and Spring Boot underneath - no JavaFX.
https://github.com/wiverson/desktop-spring-boot
Are you looking for something like this:
http://www.regexlab.com/en/jar2exe/
?
That allows the enduser to run the .exe without installing.
There are a number of options - Java web Start, 3rd party installer, etc.
Have a look at http://mindprod.com/jgloss/installer.html for an explanation.
I think that you're looking for IzPak. There is even a GUI available called PackJacket
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With