JRE Detection

One thing I have been working on lately is a web page that we can point clients to to determine browser version, screen resolution, Flash Player version, etc. Most of this is pretty easy, but determining the JRE version had me stumped for a while, mainly because I don’t really use Java that much. Googling on a few seemingly good phrases brought up old information, wrong information, or partial information. After remembering about a chapter in JSDG, and experimentation, this is what I came up with.

The first thing we can try is LiveConnect, which is present in many newer browsers (but not IE):

var java_version = java.lang.System.getProperty("java.version");
var java_vendor = java.lang.System.getProperty("java.vendor");

If LiveConnect isn’t available, then we can call methods from a simple Java applet from JavaScript. This works in all browsers.

Here is the applet:

import java.applet.*;
public class JavaVersion extends Applet
{
public String getJavaVersion ()
{
return java.lang.System.getProperty("java.version");
}
public String getJavaVendor ()
{
return java.lang.System.getProperty("java.vendor");
}
public void init () { }
public void start () { }
public void stop () { }
public void destroy () { }
}

Add the applet to a web page using the normal methods, and then you can interact with it using Javascript:

var java_version = document.javaversion_applet.getJavaVersion();
var java_vendor = document.javaversion_applet.getJavaVendor();

In the end, it turned out to be fairly easy. Here is a sample page that demonstrates everything, and a zip file with everything you need to use it yourself.

Filed under: what's cookin'

Add a Comment