• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set JAVA_HOME Dynamically?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
[Thumbnail for img.JPG]
Environment Variable Image
 
Ranch Hand
Posts: 448
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No thanks. We have all the government we need. This tiny ad would like you to leave now:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic