LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   how to get environmental variable from JAVA program (https://www.linuxquestions.org/questions/programming-9/how-to-get-environmental-variable-from-java-program-26683/)

edreddy 07-27-2002 10:45 PM

how to get environmental variable from JAVA program
 
hey! guys
I have an application in java servlets, which uses one IP address. so, everytime i run it on different machine in my LAN, I have to replace the IP address in source code and recompile the entire appication. I don't want this mess.
so, all I need is just to declare one environmental variable in my application's configuration file and export that variable to all processes that starts from that point onwards(i.e.the point where my application starts.)
but I don't know how to get that envireonmental variable value into my program.(exactly what we have getenv() function in C).
so, help me in getting getenv() kind of stuff in JAVA.
very Urgentttttttt.................................please.

sarin 07-29-2002 07:42 AM

I don't know anything of java but I have seen my friend using System class to access env vars. I have seen him using System.getProperty to do that.
--Sarin
( He told me that it is in offical java tutorial -> essentials -> system )

tda 07-29-2002 10:38 AM

Re: how to get environmental variable from JAVA program
 
Quote:

Originally posted by edreddy
hey! guys
I have an application in java servlets, which uses one IP address. so, everytime i run it on different machine in my LAN, I have to replace the IP address in source code and recompile the entire appication. I don't want this mess.
so, all I need is just to declare one environmental variable in my application's configuration file and export that variable to all processes that starts from that point onwards(i.e.the point where my application starts.)
but I don't know how to get that envireonmental variable value into my program.(exactly what we have getenv() function in C).
so, help me in getting getenv() kind of stuff in JAVA.
very Urgentttttttt.................................please.

In JDK before JDK 1.2 you was able use static method System.getenv(...) for access env varbls. But since JDK 1.2 you can't use this method because SUN decided that env vars are very system depended. This method is deprecated and throws exception. I can post java-code that can get access env variables on *NIX and Windows. But I think that you can pass IP-address as parameter to applet.


All times are GMT -5. The time now is 01:13 AM.