• 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

to set environment var. with java program

 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

how can i set environment variable (permanent) with java program on windows plateform??
i used below code but its temporory .


thanks.
milan.
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure whether you can do it using java or not but the same thing can be done in two way.
1)During production/development envn: Pass the argument to the JVM as java -DANTHOME=C:/C:/apache-ant-1.7.0 com.myapp.Main.
Get the value in your program using System.getProperties("ANTHOME");
2)Production envn: These variables can be set at the time of installation of your product with the help of package makers(InstallShield on windows) and shell scripts on Solaris/Linux.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To adjust the Windows (or any O/S) system configuration, which includes environment variables, you cannot use 100% pure Java. You can change the environment of your Java process, or any processes spawned by it, but that does not sound like what you want to do.

Your choices are (a) native code, using JNI, or (b) executing some external program using Runtime.exec(). You might be able to achieve (a) without writing any native code yourself, if you can find some that someone else has already written.
[ January 19, 2007: Message edited by: Peter Chase ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic