How to Set Environment Variables in Windows

Hi Guys,

You know that we can retrieve the environment variables using System.getProperty("JAVA_HOME"); like this. It is easy.

Can anyone tell me how to create an environment variable using System class or is there any alternate java API to create environment variable. Please let me know.

My requirement is that I want to create the environment variable as follows

DEV_HOME

D:/Java/DEV

[423 byte] By [DebadattaMishraa] at [2007-11-26 14:55:08]
# 1
Hi,You can't set environment variables using pure Java AFAIK.Kaj
kajbja at 2007-7-8 8:43:38 > top of Java-index,Java Essentials,New To Java...
# 2
Do you want to set classpath? In that case..1.Right click on my computer2click on advanced tab3.click environment variables4.edit 5.CLASSPATHand write the classpath..
KayDeEa at 2007-7-8 8:43:38 > top of Java-index,Java Essentials,New To Java...
# 3
Good day Friends! we cant set variables as you want ,like d:\Dev_Home instead of JAVA_HOME
vasu_gba at 2007-7-8 8:43:38 > top of Java-index,Java Essentials,New To Java...
# 4

Are you talking about Java System properties (get and set through System.get/setProperty) or Environment Variables (read-only, get through System.getenv)?

You can set the former, not the latter (unless you start a new process through Runtime.exec(), for which you can specify a custom environment.

Herko_ter_Horsta at 2007-7-8 8:43:38 > top of Java-index,Java Essentials,New To Java...