Java Runtime Environment Dynamic Installer

From NSIS Wiki

Author: trumpetinc (talk, contrib)


Links

Download: JREDyna.zip (4 KB) original version, based on Inetload (deprecated) plugin.
Download: JREDyna_Inetc.nsh (6 KB) version based on Inetc
Forum: [1]

Description

A header that makes it easy to add Java Runtime installation to your installer. Includes version detection, optional custom page to tell user that JRE installation is going to occur, automatic download of the latest JRE and installation.

Discussion

I've always felt that it should be *easy* to install the Java Runtime while installing our applications, and without making our installer contain the 10MB JRE installer. Sun has focused their energy on making installation easy from inside a web page, but for those of us still installing applications on workstations, no decent option is available.

There are a number of projects in the wiki that address some of the problem, but none in a way that was easy to just drop into an existing installer. Here are some examples:

The important thing about this library is that it makes it easy to drop into any installer. The end result is an installation experience that is similar to the .NET download that is part of many applications dependent on that framework.

The download URL for the Java Runtime that is shown in the examples will get the latest version of the JRE (and should continue to work, even as Sun releases new builds). [The Bundle number will change as new versions come out.] Getting the Java Runtime to install in a quasi-silent operating mode took some doing. See the Sun documentation on silent mode operation as a starting place, but be aware that Sun's installer is a small executable that downloads a larger MSI file, then calls msiexec with a bunch of command line arguments.

Dependencies

The original library is dependent on the InetLoad plug-in plugin (deprecated).
The JREDyna_Inetc.nsh‎ not found version depends on the Inetc plug-in plugin.

Usage

Include and Defines

Include the header and define two constants in your .nsi file as follows (note that the !define must come before the !include):

 !define JRE_VERSION "1.6"
 !define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=52252"
 !include "JREDyna.nsh"

JRE_VERSION is the lowest required version, not the version of the JRE to download.

If you are to use the JREDyna_Inetc.nsh version of this include file, use instead:

 !define JRE_VERSION "1.6"
 !define JRE_URL "http://javadl.sun.com/webapps/download/AutoDL?BundleId=52252"
 !include "JREDyna_Inetc.nsh"

Add page notifying user that JRE installation is required (Optional)

When declaring your pages, use the following macro to insert the JRE notification page:

 !insertmacro CUSTOM_PAGE_JREINFO

Detect, download and install JRE - if necessary

In one of your installation sections, make the following call:

 call DownloadAndInstallJREIfNecessary

Future Improvements

  • The text strings used in this page should be configurable, and should be i18n aware
  • Add option to control whether the JRE install is silent (no dialogs or progress bars displayed). Personally, I don't like having it be completely hidden as this introduces large delays with no visible user feedback - but other users may feel differently. Having the user click a couple of buttons in Sun's installer is acceptable, I think (the same thing occurs with apps that include download of .NET, for example).
  • An example or new feature re how to cause /S to the NSIS installer to make JRE installation silent, too. Same for an option to force disabling of download with a command line flag to the installer. This covers the case where an Administrator account without Java in the path is auto-installing for a different account that does. Some admins do this for security reasons.
  • Maybe make JRE_URL define optional
Personal tools
donate
ads