27
votes

I know this question has been asked many a times and all the time there is an answer which says about using an executable jar or making an .exe using launch4j or similar app.

I may sound like a novice, which I actually am.

I have been trying a few things with a Java project. I have successfully made an executable jar and also an .exe file from it. All thanks to your previous answers in SO :)

But, I want to create a installer for Windows. Like, pressing Next for 2 - 3 times(which shows all the terms and conditions etc), then a user specify a location(like C:\Program Files\New Folder\My App), then my .exe, lib folder, img folder, other important folders get pasted in the destination folder along with the .exe file and then a shortcut is created on a desktop.

Any pointers to how can I achieve this ?

7
One of the my project I used Nsis as installer. You can check it nsis.sourceforge.net/Main_Page. - bhdrkn
WiX is also a good option. - 1615903
You may also want to check out JWrapper.com, my company recently released it. It is very easy to use, is written in pure Java (so runs on any OS) and generates native apps for Mac, Windows and Linux including icons (from PNGs you provide) and signing if you have certificates for Window and Mac. - AntonyM

7 Answers

21
votes

I have been using InnoSetup for a long time. It has always worked very well. It can do everything you need (unpack files, put shortcuts on desktop, start menu etc) and generates installers that we are used to.

9
votes

If you want free and open source, you could take a look IzPack. We use this at work for its command line support in our builder.

You could also take a look install4j which is a commercial product we've trialed on and off before (but when it comes to spending money, you tend to want to know you're getting what you want ;))

4
votes

If you are on JDK 13 or above, you can package any Java program along with its runtime by using the default packaging tool in the JDK called Jpackage. This can inherently create installers for Linux, Mac and Windows operating system.

An EA of the tool is already available as a part of the JDK.

You can create a specific runtime by using jlink.

Jpackage needs some 3rd party free software for creating Windows bundles:

  • To create .exe bundle, it uses Wix
  • To create .msi bundle, it uses Inno

All the details about Jpackage can be found at JEP 343: Packaging Tool.

4
votes

Edit: I'll leave this here for reference, but note: The Java plug-in needed to launch JWS and applets was removed by browser manufacturers, and both were deprecated in Java 9 and removed from the API.

Use Java Web Start.

Like, pressing Next for 2 - 3 times (which shows all the terms and conditions etc)

The ExtensionInstallerService of the JNLP API provides this. Here is a demo. of the installer service.

..then a user specify a location(like C:\Program Files\New Folder\My App), ..

The ExtensionInstallerService provides a method getInstallPath() which..

Returns the directory where the installer is recommended to install the extension in. It is not required that the installer install in this directory, this is merely a suggested path.

That is not quite the same as what you are asking, but then I think it is generally a bad idea to allow the user that level of control.

then my .exe, lib folder, img folder, other important folders get pasted in the destination folder along with the .exe file ..

JWS installs the resources mentioned in the JNLP automatically, as and when they are needed. Further, it updates the resources if the archives on the server change.

and then a shortcut is created on a desktop.

JWS can supply desktop shortcuts and menu items on supported systems.

E.G.

1
votes

I was in the same situation a few months ago. After trying out a lot. I suggest NSIS. There is a nice plug-in for Eclipse EclipseNSIS with some templates. It helps a lot to get a basic installer with just some easy clicks. If the resulting code is not sufficient you can do the rest work by coding, but most of the code is generated by EclipseNSIS.

1
votes

You can also use Advanced Installer. Since you already have an EXE to launch your JAR, you don't need to use the Java Launcher support from Advanced Installer, you can create a Simple project, which is available in the free edition, so you don't need to purchase a license.

It will take you maximum 10 minutes to install it and create the setup package, as you will see it is very easy to learn using it.

0
votes

use Launch4j to create exe file. you must give the relative path to jre folder. next use Inno Setup to make setup. You can bundle jre inside the installer. I've use it and it works like a magic. I can show details.