Computing.Net > Forums > Programming > Find latest JRE in batch file

Find latest JRE in batch file

Reply to Message Icon

Original Message
Name: sujie
Date: June 29, 2007 at 08:33:23 Pacific
Subject: Find latest JRE in batch file
OS: Windows
CPU/Ram: 1 GB
Comment:

Hi,

I need to find the latest JRE from my system and assign it to JAVA_HOME in my batch file.
I know the directory where the JRE files are located and directory can be initially hardcoded.
So from that directory i need to find the latest and assign it to JAVA_HOME variable.


Any help will be very useful.

Sujie


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: June 29, 2007 at 13:17:53 Pacific
Subject: Find latest JRE in batch file
Reply: (edit)

To satisfy your need is quite straightforward, but as my knowledge of Java programming is close to zero, please give me the following info

- does the directory to scan hold just JRE files or is there a blend of files? If just JRE, ignore next question.

- which is the pattern in filename that makes JRE files unique (e.g. they begin with java or have a specific extension)?

- does the JAVA_HOME variable have to hold just the filename selected or its whole path?

Please, as a general rule remember to give the most specific and clear info when posting, starting from the OS (Windows is too generic as it is a trading logo sheltering absolutely different products lines, e.g. Win 98 vs. XP).



Report Offensive Follow Up For Removal

Response Number 2
Name: tonysathre
Date: June 29, 2007 at 14:10:41 Pacific
Subject: Find latest JRE in batch file
Reply: (edit)

@echo off
for /f "tokens=2 delims=e" %%i in ('dir /b "%programfiles%\java"') do (
set java_home=%%i
)
echo %java_home%

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 3
Name: sujie
Date: July 2, 2007 at 01:36:17 Pacific
Subject: Find latest JRE in batch file
Reply: (edit)

Thanks tonysathree..it was of great help..
I assigned the output of your code to JRE_VERSION and i did this in my code
SET JAVA_HOME = C:\Program Files\Java\jre%JRE_VERSION%;

But the value of JAVA_HOME after executing this line is only jre1.4.0_1 not as expected as with the complete path.

Please help me if you know what is the problem..or i want the full absolute path from your output of the code instead of jre version alone.

Thanks in advance for your help

Sujie


Report Offensive Follow Up For Removal

Response Number 4
Name: tonysathre
Date: July 3, 2007 at 21:02:22 Pacific
Subject: Find latest JRE in batch file
Reply: (edit)

If you want the full path in the output, this will work:

@echo off
for /f %%i in ('dir /b "%programfiles%\java"') do (
set jre_version=%%i
)
echo %programfiles%\java\%jre_version%
pause


Report Offensive Follow Up For Removal

Response Number 5
Name: sujie
Date: July 4, 2007 at 01:03:11 Pacific
Subject: Find latest JRE in batch file
Reply: (edit)

Thanks a lot..It was of great help..

It was very nice of you to help me in this forum..:-) and your code was pretty clear and straight forward.

I really appreciate your help.

Thanks again

Sujie


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Find latest JRE in batch file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge