Changing Java Version for a Specific Program

前端 未结 3 1173
挽巷
挽巷 2021-01-24 23:25

If I have more than one version of Java installed can I specify the version I want to kick a program off with via batch file, or do I have to change my environment variable? If

3条回答
  •  情歌与酒
    2021-01-25 00:20

    If your batch file executes the Java program as:

    java  com.stackexchange.MyProgram  argument1 argument2 etc
    

    You can change it to execute it using a specific Java installation as:

    "C:\Program Files\Java\jdk1.6.0_20\bin\java.exe"  com.stackexchange.MyProgram  argument1 argument2 etc
    

    Or you can declare a variable and use it (this is useful if you have a master batch file that sets up the environment for your mini batch files):

    :: In master batch ::
    SET JAVA_HOME=C:\Program Files\Java\jdk1.6.0_20\bin
    
    :: In mini batch ::
    "%JAVA_HOME%\java.exe"  com.stackexchange.MyProgram  argument1 argument2 etc
    

提交回复
热议问题