How to distribute Java Application
Asked Answered
D

5

8

I would like to know about the various options for distributing a Java application.

I know that you can

  • Distribute the Source Code and let users compile it themselves, or provide make files, etc..
  • Package it into a JAR, and have self extracting archives
  • and (I'm sure, myriad other ways)

I'm hoping for some explanations about the most common options (and one's I haven't thought of) and in particular, do they require a user to have a JVM, or can it be bundled with one - personally I'm not too fond of an installer which halts due to a lack of JVM. Who says an app needs an installer, stand-alone solutions are fine too.

Also, worth asking is how to handle cross-platform distributing, exe's vs dmg's, etc...

My primary motivation for this question (which I appreciate is similar to others) is to find solutions that don't require the user to already have a JVM installed - but for completeness, I'm asking generally.

Thanks very much

Dario answered 22/2, 2011 at 16:39 Comment(0)
M
6

Distribute the Source Code and let users compile it themselves, or provide make files, etc..

This is probably ok for open source projects, but very unusual for anything commercial. I'd recommend providing it as an option for the techies, but distributing JARs also

Package it into a JAR

I'd call this the best practice

and have self extracting archives

How about making the jar executable instead?

I'm hoping for some explanations about the most common options (and one's I haven't thought of) and in particular, do they require a user to have a JVM, or can it be bundled with one - personally I'm not too fond of an installer which halts due to a lack of JVM.

I don't think it's legal to bundle JREs. That said, it's rather obvious that a java-based solution won't work without Java. OpenOffice and many others fail to install without an installed JRE. I'd say that's understandable and OK.

IzPack seems to be a good solution to create Java-based installers.

My primary motivation for this question (which I appreciate is similar to others) is to find solutions that don't require the user to already have a JVM installed

As I wrote, I think it's not legal to bundle the JRE [UPDATE: it is legal, read this document for reference] (and also not a good option, as you'd have to bundle many different OS / architecture combinations). So the only other way would be native compilation (can't help you with that, sorry).

Matta answered 22/2, 2011 at 16:50 Comment(5)
+1 for executable JAR. If you need supplementary files or special VM args (like I do with an application that uses external DLLs etc), provide batch startup files - .bat for Windows, or .sh for linux/unix and pack it all into a single zip file. Installation is just a matter of extracting the zip.Siqueiros
Thanks. From following your link to #2306262 I also found JSmooth which claims: "If no VM is found [...] with jsmooth: the wrappers can redirect them to a web page, or even better, they can propose the user to automatically download and install a Java Environment". Would you say it's the likelihood that a JRE is installed that still makes JARs best practice over a solution such as this?Dario
@Dario no this sounds even betterMatta
OK, Thanks. It's a shame Sun/Oracle haven't done anything like this. I suppose JARs suffice for the vast majority of cases though.Dario
@SeanPatrickFloyd, Distributing as jar isn't user friendly, if the user deletes the JRE ....Nonsuit
S
3

InstallBuilder allows you to easily distribute Java applications and bundle a JVM (although itself does not require Java, so as you mention you will never get errors because the end user does not have a JVM in the machine). It is a commercial product (diclaimer, I am the original developer) but we have discounts for small ISVs and free licenses for open source projects. It is in use by MySQL/Oracle, Jaspersoft, Alfresco, Pentaho and a bunch of other ISVs with Java-based tools and those apps have been downloaded literally millions of times with no major issues. Give it a try :)

Spark answered 8/5, 2011 at 2:11 Comment(0)
H
2

Standalone app

In modern Java, you can produce a stand-alone app with a bundled JVM for a particular host OS.

For background info, read the Oracle white paper, Java Client Roadmap Update, updated 2020-05.

Modularize

First, modularize your app to support the Java Platform Module System. You can learn about this in books, presentation videos, and many blog posts.

One of the benefits of modularization is that the bundled JDK can be stripped down to include only the parts you are actually using in your app. This results in using less storage and less memory.

Obtain a Java implementation

Second, obtain an implementation of Java whose licensing terms meet your needs. Terms vary. Some are free-of-cost and some are commercial products.

Here is a flowchart I made to assist you in choosing.

enter image description here

Build the final app

Third, use tools such as jlink and jpackage to build the standalone app.

The tooling for this process is quickly evolving. So there may be additional tools coming to market.

Your bundled JDK has native code aimed at a particular host OS. So you will need to make a separate build of your app for each deployment platform you choose to support.

By the way, be sure to check the licensing terms of every library you include within your app.

Alternative: GraalVM

An alternative approach to ahead-of-time compile to native code using the GraalVM. This is bleeding-edge technology, so beware, but is quite promising.

Hooknosed answered 1/12, 2020 at 20:56 Comment(0)
M
1

In general, you have a few options:

1) Java Web Start
2) Run it as an applet
3) download and install.

You are primarily interested in option 3. You have a variety of installers (InstallJammer is one, but you have others) that you can create installation packages for. Since you are looking at distributing the JVM (which you can do), then you are looking at different installer for every platform you are targeting.

Marysa answered 22/2, 2011 at 16:51 Comment(0)
D
0

For simple products, I like to get a single executable jar. See http://one-jar.sourceforge.net/

For any big products and installer will be needed. (InstallAnywhere, Install4J, LzPack etc will help you to create one)

Daveta answered 22/2, 2011 at 17:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.