This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set JAVA_HOME Dynamically?

 
S. Vijay
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone

I am trying to set JAVA_HOME dynamically. I am trying to set the value in the registry but that is not getting refreshed. For example my scenario is this

1) Run a java Program
2) User selects one java version out of many available java versions
3) User clicks a button which internally takes the input and changes the java version.

I tried doing the following code snippet



On doing the above I could able to change the registry value but when I run java applications it is still using the previous java version not the changed one.

Can anyone help me how to change the java version by using the registry or by any other means?

Please note that setx command cannot be used in my machine since mine is Windows XP so it would be very helpful if anyone help me to provide a solution other than what mentioned.

Thanks
Vijay
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither java nor javac take any notice of JAVA_HOME . Some applications such as Tomcat use JAVA_HOME in their startup scripts but Java does not use JAVA_HOME.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
S. Vijay wrote:
mine is Windows XP so it would be very helpful if anyone help me to provide a solution other than what mentioned.


hmm. good even I am using xp. as james said JAVA_HOME is used by some other application needs to find out where is java has been installed.if you want more specific answer then elaborate.
 
S. Vijay
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I will explain in detail what I am trying to do

Please see the attachment image

When I change the Java home version then my jdk version gets changed if I use the Environment Variables from System Properties windows GUI.

For example if I am using JDK1.5 and if I change the JAVA_HOME version to JDK1.6 then the java version changes to the corresponding 1.6 version.

So in my application I created a combo box which displays the different java version and when the user selects the version of his choice and click the change button then my application has to change the java version to the corresponding version.

I tried the code which was mentioned in my first post. This makes change to the registry variable and I can see the corresponding changes in the environment variable settings but still I see previous java version used not the changed one.

Please let me know if I am not clear.
img.JPG
Environment Variable Image
[Thumbnail for img.JPG]
 
Sunny Bhandari
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be the issue is that you need to close and reopen the command window to see the new changes (assuming the environment variable has really changes)

You can try changing JAVA_HOME from one command window and see that changes are not reflected in the other command window.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic