简体   繁体   English

在Windows中更改JAVA_HOME系统变量的脚本

[英]Script to Change JAVA_HOME System Variable in Windows

I do most of my work against JDK 1.5 - but occasionally I have to change to 1.6. 我做的大部分工作都是针对JDK 1.5的 - 但偶尔我必须改为1.6。 it is a bit painful to have to manually go and change my 'JAVA_HOME' system variable whenever I need to work on a project specific to one or the other (and no, Eclipse doesn't play well in these scenarios - trust me...I've tried.) 每当我需要处理特定于一个或另一个的项目时,必须手动去改变我的'JAVA_HOME'系统变量有点痛苦(不,Eclipse在这些场景中不能很好地发挥作用 - 相信我...... 。我试过了。)

I'm looking for a registry script or windows shell script or for that matter any means by which I can "toggle" this system variable with something that is easy to run. 我正在寻找一个注册表脚本或Windows shell脚本,或者就此而言,我可以用一些易于运行的东西“切换”这个系统变量。

I've messed with the 'set' command, but that only sets the variable for that particular command instance - not globally. 我已经搞乱了'set'命令,但是它只为该特定命令实例设置变量 - 不是全局的。

Thanks in advance. 提前致谢。

EDIT #1: Points of advise: 编辑#1:建议点:

  • Use the JAVA_HOME variable in your path variable as well, that way you only have to change the JAVA_HOME (which is used in many projects anyways [maven, ant, etc]) 在路径变量中也使用JAVA_HOME变量,这样你只需要改变JAVA_HOME (无论如何在许多项目中使用[maven,ant等])
  • Write the command into a couple batch scripts for easy use 将命令写入几个批处理脚本以便于使用
  • When you make the change the windows command session will not reflect it right away. 进行更改时,Windows命令会话不会立即反映出来。 You must close and reopen it. 你必须关闭并重新打开它。

You could use setx for that purpose 您可以将setx用于此目的

Like so: 像这样:

setx /M JAVA_HOME "C:\Program Files (x86)\Java\jdk1.6.0_17"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM