开发者

Change environment variable (JAVA_HOME) without logging out

开发者 https://www.devze.com 2023-03-23 10:20 出处:网络
I\'m currently developing in 3 different Java versions and therefore often change my JAVA_HOME variable. However, I have to log out in order to get the variable updated. I update it via System Propert

I'm currently developing in 3 different Java versions and therefore often change my JAVA_HOME variable. However, I have to log out in order to get the variable updated. I update it via System Properties -> Advanced -> Environment Variables (Windows XP).

Surely there is a smarter/easier way of doing this.

I g开发者_StackOverflow社区uess I could use the SET command in prompt, but that is not permanent and as I often use one Java version for a period of time I don't want to reset it every time I start the PC.

Any suggestions?


You don't have to log out to get an environment variable to stick, but you do have to restart whatever processes you're interested in. So for example, if you're using the command prompt, you will need to kill the command prompt and start a new one.


You could create 3 .bat files, each setting the JAVA_HOME variable and then starting your Development Environment.


I typically have separate entries in the environmental variables for separate JDKs or JREs:

  • JDK141
  • JDK156
  • JDK1624

And when needed change the JAVA_HOME variable to refer to one of those:

  • JAVA_HOME = %JDK156%

Add that to what Jon and Tim suggested and you get a very flexible way to switch versions.

Also remember that you can do

c:/program files/java/jdk156/bin/java.exe YourFolder/YourClass

As long as what you use isn't referring directly to JAVA_HOME you can force the use of a specific JRE/JDK if you specify the path in your command.

Cheers, Wim


Have the latest version of the SDK installed (7 at this time), then use the Cross-compilation options of javac when compiling.


to change the Java home without restarting or re-logging: Open Command prompt and type "set JAVA_HOME=C:\Program Files (x86)\Java\your jdk folder" then press enter. This will change the current environment settings until you restart or re-log to your windows account then it will read the settings from the windows environment settings. If you want the new settings to be permanent go to System Properties -> Advanced -> Environment Variables and change the JAVA_HOME settings

I hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消