| Author |
how to run a jar file from the cmd prompt using a specific jre version
|
Moieen Khatri
Ranch Hand
Joined: Nov 27, 2007
Posts: 144
|
|
Hi All,
I am facing an issue where I need to run a jar file from cmd.
This jar was compiled using jdk 1.5.The server from where I run this jar file has jdk 1.4 and jre 1.4 set in the path.
I don't have the necessary permissions to modify this path from the environmental variables because of business issues.
I tried to set the path from cmd prompt using the below command
set path=%path%; "C:\Program Files\Java\jre1.5.0_05\bin"
now when I check the version of the java jre again it still shows the older version 1.4
I cannot override the path variable using
set path="C:\Program Files\Java\jre1.5.0_05\bin"
as it affects the other variables.
Please can someone help me with a workaround for this issue so that I can run the jar from cmd while at the same time run it using jre1.5?Is there any such command which allows setting the jre version at the same time while running the jar?
Many Thanks in advance!
Moieen
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
set path=%path%; "C:\Program Files\Java\jre1.5.0_05\bin"
Change to
set path="C:\Program Files\Java\jre1.5.0_05\bin";%path%
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Moieen Khatri
Ranch Hand
Joined: Nov 27, 2007
Posts: 144
|
|
Thanks Deepak!
The issue seems to be resolved
Best Regards
Moieen
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
Moieen Khatri wrote:Thanks Deepak!
The issue seems to be resolved
Best Regards
Moieen
The cause, in case any one stumbles on this thread later, is that another JRE was in the path and the OS always picks the first matching java.exe from the path
|
 |
Moieen Khatri
Ranch Hand
Joined: Nov 27, 2007
Posts: 144
|
|
Hi Deepak,
Thanks for the explaination of the cause.
It was very helpful for me
Best Regards,
Moieen
|
 |
Mikhail Balanov
Greenhorn
Joined: Nov 06, 2012
Posts: 1
|
|
Also you can just restrict java version:
java -version:"1.6*"
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
Welcome to the Ranch
If we are reopening old threads, I shall add my tuppenceworth: you can quote the direct path to the java executable:
"C:\Program Files\Java\jre1.5.0_05\bin\java" MyClass
Because there is a space in “Program Files”, you will probably have to enclose the first part of that instruction in "quotes".
|
 |
 |
|
|
subject: how to run a jar file from the cmd prompt using a specific jre version
|
|
|