This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes setting system envarioment variables in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "setting system envarioment variables in java" Watch "setting system envarioment variables in java" New topic
Author

setting system envarioment variables in java

garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
guys,
How do I set Enviroment variables(JAVA_HOME,MYSQL_HOME...) and different addresses in the system Path using java code?
Thanks

Yossi
Joni Salonen
Ranch Hand

Joined: Jan 07, 2006
Posts: 53
What are you trying to do?

A process can only change the copies of the environment variables of itself and set the environment of child processes it might spawn, so setting them is fairly useless.
[ February 19, 2006: Message edited by: Joni Salonen ]
garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
hey,
All I'm trying to do is to set through the code different settings for JAVA_HOME and PATH.
I have an installation kit and each compter has different settings.
Now I use a setEnv.cmd file:
System\Service\setx JAVA_HOME c:\j2sdk1.4.2_02 -m
set JAVA_HOME=c:\j2sdk1.4.2_02
System\Service\setx MYSQL_HOME c:\mysql -m
set MYSQL_HOME=c:\mysql
System\Service\setx path "c:\j2sdk1.4.2_02\bin;c:\Eldat Common Path;c:\perl\bin;%path%" -m
set path=c:\j2sdk1.4.2_02\bin;c:\Eldat Common Path;c:\perl\bin;%path%;


The problem here is the static addresses, If I set it in the code it can be dynamic.

Can I do it?

thanks
Yossi
Joni Salonen
Ranch Hand

Joined: Jan 07, 2006
Posts: 53
I don't really undestand the problem --- why don't you just make the part with for example "c:\j2sdk1.4.2_02" configurable instead of hardcoding it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting system envarioment variables in java