11

How can I make a java program installable?

I have an application saved in my Eclipse workspace.

I can export it as a .jar file.

This is for a "real-world" application.

How can I export to be a ".exe" file or ".dmg" so that it can be installed on another machine?

Since Java is platform-independent I think it is a matter of exporting for a specific operating system.

I've googled a lot and read so many different stories, so I would prefer an answer from an experienced person.

Paul
  • 23,002
  • 11
  • 77
  • 112
JBoy
  • 4,834
  • 12
  • 54
  • 89
  • possible duplicate of [compiling-a-java-program-into-an-exe](http://stackoverflow.com/questions/2011664/compiling-a-java-program-into-an-exe) – asgs Apr 19 '11 at 06:12
  • 1
    This is actually two questions in one. Creating a launcher (.exe for Windows and .app for OSX) and then creating a installer (.msi for Windows and .dmg for OSX). Did you check whether just shipping an executable JAR is an option? – Dakshinamurthy Karra Apr 19 '11 at 06:15
  • Dup:http://stackoverflow.com/questions/147181/how-can-i-convert-my-java-program-to-an-exe-file – Sajad Bahmani Apr 19 '11 at 06:19
  • @asgs, that is for Windows only. – Thorbjørn Ravn Andersen Apr 19 '11 at 06:43
  • This kind of questions has been asked many times...one of them is my post http://stackoverflow.com/questions/5646813/how-to-make-exe-file-for-izpack-installer-jar-file/5647255#5647255 Apart from that, you may optionally set your setup to bundle a JRE or ask for Java download using any of the tools mentioned – eee Apr 19 '11 at 08:07
  • buying a new computer, nowadays, comes with an already installed JVM. This is included in most standard installation packages (an any good thech guy will include it). For enterprise workstations, the IT department is responsible to install it anyway. Even Netbeans (and apparently also Eclipse) don't come bundled with the JVM anymore. That has to say. – Yanick Rochon Apr 19 '11 at 13:19
  • Some IT managers don't like Java installed for some reasons only they could comprehend :) – eee Apr 19 '11 at 13:50

6 Answers6

9

I guess what you are looking for is not only to make the program runnable (as lobster1234 proposed) but to make it actually installable. We have recently used IzPack. It actually looks nice.

There are also some decent tutorials on the details here and here

kostja
  • 56,537
  • 45
  • 164
  • 213
4

Jar files are usually the way to go, since the JVM can directly execute the packaged files through the java -jar <jarfile> command. Java WebStart is good if you want to distribute your app from a web site, etc. However, some OS don't have that "feature" installed, even if the JVM is there. Another solution is to have at least 3 scripts to launch your app (batch for Windows, shell script for Linux, and whatever Mac needs -- sorry, don't have a Mac -- ).

Don't create native executable files (i.e. exe for Windows), they are redundant since you already have a JVM for that.

Yanick Rochon
  • 45,203
  • 21
  • 112
  • 182
  • JAR-files does not hold an icon under Windows yet. – Thorbjørn Ravn Andersen Apr 19 '11 at 06:44
  • There is a reason why jar distributed as EXE is a viable option considering that with EXE process you can attach `AppUserModelID` properly for a proper Jump List interaction in Windows 7 especially during pinning a taskbar combined with a setup installer that supports a Windows shortcut with `AppUserModelID` property – eee Apr 19 '11 at 12:06
  • isn't the point of Java being able to write platform independent applications? Having an .exe file renders that pointless; might as well generate an executable for Linux and Mac in that case. You *can* have an icon with a launcher, in any OS now. That argument does not carry much weight. – Yanick Rochon Apr 19 '11 at 12:39
  • Being platform-independent is what Java is touted for since the beginning. But, when it comes for a full support for the capabilities available to the target OS (in the case of various Windows OS versions), we have to adapt it anyway. The standard java.exe and javaw.exe are not enough. So, using a launcher or installer solution helps to compliment them on the target OS. – eee Apr 19 '11 at 12:53
  • I'm sorry if I don't agree with your point of view. If a Java application needs "full support for capabilities available to the target OS", it will use JNI and OS dependent native libraries wrapped in some abstract classes (adapters). Many applications do that already. But that is besides the point. Most Java applications only requires a Jar file, and a launcher; if you don't need to play with security policies or setup some third party service, you don't *need* an installer. – Yanick Rochon Apr 19 '11 at 13:14
  • What you've said just now is what I normally do exactly for certain cases of deployment especially under Windows. Back to the case with `AppUserModelID` under Windows 7 earlier, I have to call Shell32's `SetCurrentProcessExplicitAppUserModelID()` through JNA to register a Java app so it will work correctly when pinning its Jump list to the taskbar. Thanks to `InnoSetup` support for `AppUserModelID` embedded shortcut, invoking the app from a shortcut that has been pinned to the taskbar will work correctly as well. – eee Apr 19 '11 at 13:33
2

As of Java 8, jdk is now capable of generating it's own Installables for Windows, OSX, and Linux. However, on Windows it depends on either Inno Setup 5 or later or WiX 3.0 or later.

https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/self-contained-packaging.html#A1324980

The easiest way to produce a self-contained application is to modify the deployment task. <fx:deploy width="${javafx.run.width}" height="${javafx.run.height}" nativeBundles="all" outdir="${basedir}/${dist.dir}" outfile="${application.title}"> <fx:application name="${application.title}" mainClass="${javafx.main.class}"/> <fx:resources> <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/> </fx:resources> <fx:info title="${application.title}" vendor="${application.vendor}"/> </fx:deploy>

efaj
  • 888
  • 1
  • 11
  • 22
2

I'm risking a flamewar here but I'm game :) Unless you're on a platform where the JRE is already known to exist (ex. OS X) it's going to be a hassle for you and/or end users. The problem is java apps are simply not standalone and depend on a massive framework.

The JRE, Java Web Start, or whatever you use has to be put on the target system. Also you have to have a launcher of some sort. It could be something as simple as a script which runs java, supplies the classpath, etc. This wouldn't be needed if java "compiled" to an .exe or something but that's just how it works.

This is one of the reasons I've turned off on deploying Java to end-user machines. It's just a lot of trouble. I once worked on a project where we actually embedded an entire private jre that got deployed by the installer. It wasn't pretty but it got the job done.

seand
  • 5,044
  • 1
  • 21
  • 35
1

Guys already gave you a lot of options so I do not want to mention them again. The only option that is missing here is a case when you really need to install your program, meaning execute some logic, modify (or at least read) system configuration, create desktop shortcuts, copy many files, configure third party products (that are probably already installed) etc.

In this case you can use InstallAnywere, EzPack or similar solutions (see http://java-source.net/open-source/installer-generators) For example if your project is relatively simple I'd recommend you AntInstaller.

BTW if you afraid that your customer probably does not have JRE installed on his machine you can package your code (or better a loader) using Launch4J that generates executable from your java code.

AlexR
  • 109,181
  • 14
  • 116
  • 194
0

You can use Java WebStart, or package the program as an executable jar file.

lobster1234
  • 7,555
  • 24
  • 29