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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Find latest JRE in batch file

Reply to Message Icon

Name: sujie
Date: June 29, 2007 at 08:33:23 Pacific
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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 29, 2007 at 13:17:53 Pacific
Reply:

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).



0

Response Number 2
Name: tonysathre
Date: June 29, 2007 at 14:10:41 Pacific
Reply:

@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


0

Response Number 3
Name: sujie
Date: July 2, 2007 at 01:36:17 Pacific
Reply:

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


0

Response Number 4
Name: tonysathre
Date: July 3, 2007 at 21:02:22 Pacific
Reply:

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


0

Response Number 5
Name: sujie
Date: July 4, 2007 at 01:03:11 Pacific
Reply:

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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Find latest JRE in batch file

Date Routines in Batch Files www.computing.net/answers/programming/date-routines-in-batch-files/15590.html

key-combination in batch file www.computing.net/answers/programming/keycombination-in-batch-file-/16782.html

%DATE% in batch files with win98 www.computing.net/answers/programming/date-in-batch-files-with-win98/4007.html