更改特定程序的Java版本 [英] Changing Java Version for a Specific Program

查看:100
本文介绍了更改特定程序的Java版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我安装了多个Java版本,是否可以通过批处理文件指定要启动程序的版本,还是必须更改环境变量?如果必须更改环境路径,当前正在使用其他版本的程序会停止运行吗?我在想不,但想确定一下.

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 I have to change the environment path will the programs that are currently using the other version stop working? I'm thinking no but wanted to make sure.

我有以下批处理文件可以随时更改版本,但似乎无法正常工作- http://pastebin.com/4S6xYHan

I have the following batch file in place to change versions on the fly but it doesn't seem to work- http://pastebin.com/4S6xYHan

编辑-更新了批处理文件.

Edit- Updated batch file.

推荐答案

如果您的批处理文件以以下方式执行Java程序:

If your batch file executes the Java program as:

java  com.stackexchange.MyProgram  argument1 argument2 etc

您可以将其更改为使用特定的Java安装执行它,如下所示:

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

或者您可以声明一个变量并使用它(如果您有一个 master 批处理文件为您的 mini 批处理文件设置环境,这将非常有用):

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

这篇关于更改特定程序的Java版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆