12

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.

7
  • possible duplicate of compiling-a-java-program-into-an-exe Commented Apr 19, 2011 at 6: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? Commented Apr 19, 2011 at 6:15
  • Dup:stackoverflow.com/questions/147181/… Commented Apr 19, 2011 at 6:19
  • @asgs, that is for Windows only. Commented Apr 19, 2011 at 6:43
  • This kind of questions has been asked many times...one of them is my post stackoverflow.com/questions/5646813/… Apart from that, you may optionally set your setup to bundle a JRE or ask for Java download using any of the tools mentioned Commented Apr 19, 2011 at 8:07

6 Answers 6

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

Sign up to request clarification or add additional context in comments.

Comments

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.

6 Comments

JAR-files does not hold an icon under Windows yet.
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
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.
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.
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.
|
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.

Comments

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>

Comments

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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.