Changing Java Version for a Specific Program

前端 未结 3 1171
挽巷
挽巷 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:07

    You batch file is ok.

    You can use SET command on a terminal to set your JAVA_HOME and also add it to your path variable and that's enough to run an app with the jdk you want.

    Remember that if you set it through terminal the variable will work on that terminal and last during that terminal is open.

    If you want to cover the scope for you SO you need to set in windows variables:

    enter image description here

    For linux you need to use export command the variables

    0 讨论(0)
  • 2021-01-25 00:12

    If you want to do it for a specific instance of a program why not specify the full path, e.g.

    if "%1" == "6.20" (
    
    'C:\Program Files\Java\jdk1.6.0_20\bin\java.exe' -version
    

    )

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题