简体   繁体   中英

How can I package a Java desktop application?

I am working on a simple desktop java application. I would like to make it as seamless to install for end users as possible. Eg similar to how Minecraft is distributed - a simple executable for OS X and an EXE file for Windows.

What tool should I use?

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.

Executable Java Wrappers

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 .

Installers

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 , …

Java Web Start

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 .

Bundle JVM within your app

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.

Compiled native app

GraalVM

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 .

Project Leyden

Possibly related: Oracle's Project Leyden. See initial announcement by Mark Reinhold , and see this article , 2020-05-07.

Java Web Start phase-out

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 ..

Other matters

..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 2 nd 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM