tags:

views:

294

answers:

3

Sun's Deployment Toolkit contains a function for installing a specific JRE version, but it requires the use of a web browser. How can a desktop application download the JRE programmatically (without the use of a browser)?

+1  A: 

You can use java web start to launch an application from a desktop shortcut as well. If you do, then the web start framework can download and install JREs just as if it was started from a browser.

If you distribute the application as a browser based web start application then you can set properties in the jnlp file that creates start menu and/or desktop icons on first launch. If you choose another distribution form you can manually create a shortcut that will call javaws instead.

henrik
Would'nt you need a JRE to use Java web start in the first place?
Ryan Fernandes
Yes, I assumed that the desktop application was developed in Java but like you've pointed out this isn't necessarily the case. If it isn't java web start won't help.
henrik
A: 

You can use JSmooth to check for Java at launch time, which will then allow for the user to install it.

If you want a silent install, you need the MSI version (for Windows), which is as far as I know not publicly available.

Thorbjørn Ravn Andersen
A: 

You might want to check out Sun's kernel installer for Java - it's fairly small, and takes care of downloading and installing out to a full JVM in the background. Depending on how you deploy your app, this might be small enough to just include it. In our app, even this installer is too big, so we detect the current installed JRE, then download the kernel installer if we detect that it's necessary.

You can always use an http download (outside of a Web browser) from your installation system to get the kernel installer, then run it. We use NSIS and there are a number of http download libraries that work quite well for this. There are also several NSIS plugins that can detect the correct version of Java. The combination of those two pieces of functionality have always been sufficient for us.

EDIT - if you are using NSIS, here's a plugin that will download a file via http or ftp from inside the installation.

and here's a full featured Java launcher using NSIS. I don't care for the specific technique of actually starting the app - using javaw.exe - but the general approach of detecting the JRE version, UAC elevation, downloading the JRE installer is sound. We have our own launcher (instead of java.exe) that allows us to have our own process name, icons, etc...

Personally, I recommend doing this sort of work in the installation itself.

Kevin Day
Fair enough, but then how do you download the Java Kernel installer programmatically?
Gili
Are you wanting the download to be initiated by your application (assuming you have a native .exe that is starting up the JVM)? Or by the installer? The most likely scenario is via the installer, in which case it's going to depend a whole lot on your installation technology. I've updated the answer to include a link for how to do http downloads in NSIS. If you use a different installer mechanism, you'll have to find an equivalent.
Kevin Day