Jon
Jon

Reputation: 3194

Running two versions of Java in cmd

I have configured my JAVA_HOME to point to java 8, but require the use of Java 7 for a different application. Is there a way of easily switching between the two?

I have tried to define another environment variable called

JAVA7 C:\Program Files\Java\jre7\bin\java.exe

but I am not sure running:

%JAVA7% program.jar

is the correct method, as I keep getting the error:

'C:\Program' is not recognized as an internal or external command, operable program or batch file.

Upvotes: 2

Views: 109

Answers (3)

user4310454
user4310454

Reputation:

We can point only one version of java in JAVA_HOME

so create a batch file with

set JAVA_HOME="path-to-java-home"
set path="path-to-java-home\bin"
<your-application>.exe or <your-application>.sh

above lines are used to overwrite existing system environment JAVA_HOME variable.

Upvotes: 2

SMA
SMA

Reputation: 37023

use double quotes as below:

"%JAVA7%" program.jar

Upvotes: 1

Maroun
Maroun

Reputation: 95948

See that space you have between "Program" and "Files"? It makes problems. Use:

JAVA7 C:\"Program Files"\Java\jre7\bin\java.exe
         ↑             ↑ 

Or:

"%JAVA7%"

instead.

Upvotes: 2

Related Questions