Find latest JRE vesion in batch file

Hi,

I have a batch file which sets the java runtime path before running my program. I have multiple versions of JRE installed( the same is possible in client as well). I need to find the latest JRE version from a Windows system and set that in classpath in the batch file.

Any inputs on how to do this?

Thanks,

Sujie

[347 byte] By [Sujiea] at [2007-11-27 7:32:41]
# 1

you can list all the installed JVMs using a registry reader program like the following:

import java.util.Iterator;

import ca.beq.util.win32.registry.RegistryKey;

import ca.beq.util.win32.registry.RegistryValue;

import ca.beq.util.win32.registry.RootKey;

public class RegistryReader {

private static final String INSTALLED_JVM_REG = "SOFTWARE\\JavaSoft\\Java Runtime Environment";

public static void main(String[] args) {

RegistryKey r = new RegistryKey(RootKey.HKEY_LOCAL_MACHINE, INSTALLED_JVM_REG);

//Get Current Version

RegistryValue v = r.getValue("CurrentVersion");

//System.out.println(v.toString());

if (r.hasSubkeys()) {

Iterator i = r.subkeys();

while (i.hasNext()) {

r = (RegistryKey) i.next();

//System.out.println(x.toString());

System.out.println(r.getValue("JavaHome").toString().substring(16));//16 = "JavaHome:REG_SZ:".length();

} // while

} // if

}

}

To run this program, you'll need a reg utility from http://www.bayequities.com/tech/Products/jreg_key.shtml. Basically you'll need jRegistryKey.jar and jRegistryKey.dll.

You should then compare the values JavaHomes and find the latest JVM.

java_2006a at 2007-7-12 19:13:02 > top of Java-index,Desktop,Runtime Environment...
# 2

@echo off

::Find the current (most recent) Java version

start /w regedit /e reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment"

type reg1.txt | find "CurrentVersion" > reg2.txt

if errorlevel 1 goto ERROR

for /f "tokens=2 delims==" %%x in (reg2.txt) do set JavaTemp=%%~x

if errorlevel 1 goto ERROR

echo Java Version = %JavaTemp%

del reg1.txt

del reg2.txt

::Get the home directory of the most recent Java

start /w regedit /e reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\%JavaTemp%"

type reg1.txt | find "JavaHome" > reg2.txt

if errorlevel 1 goto ERROR

for /f "tokens=2 delims==" %%x in (reg2.txt) do set JavaTemp=%%~x

if errorlevel 1 goto ERROR

echo Java home path (per registry) = %JavaTemp%

del reg1.txt

del reg2.txt

RealHowToa at 2007-7-12 19:13:02 > top of Java-index,Desktop,Runtime Environment...