Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

@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

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

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

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

![]() |
![]() |
![]() |

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