aspose file tools*
The moose likes Java in General and the fly likes how to run a jar file from the cmd prompt using a specific jre version Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to run a jar file from the cmd prompt using a specific jre version" Watch "how to run a jar file from the cmd prompt using a specific jre version" New topic
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: 6657
    
    5

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 - More SCJP Mocks
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: 6657
    
    5

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: 36465
    
  15
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".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to run a jar file from the cmd prompt using a specific jre version
 
Similar Threads
Connection OK in JDK1.3, but fails in JDK1.4
Intermediate/Advanced Java Users. Pl help with static profilers (PMD)
How to use JDK & JRE without setting the path in environment variable
javac not making a .class file
Wrong version appearing for "java" command