Link to home
Start Free TrialLog in
Avatar of jernhung
jernhung

asked on

Environment Variables

Hi,

I have set an environment variable in my system, and I'm trying to make my Java client get this variable. This variable is pointing to a folder name.

ie APP_HOME=E:\Application\Shared

Since System.getenv(...) has been deprecated, I'm using System.getProperties(...). But apparently, this only gets the variables with regards to the existing JAVA environment, not any variable that I have set on my OS (which happens to be WinNT)

Is there any way for me to read it?

Alternatively, this lack of support, IMHO, may suggest that the Java implementors would like developers to handle environment variables somewhat differently. If that's the case, can someone enlighten me on what this alternative method may be?


Thanks

Regards
JH


Avatar of exorcist
exorcist

I tried this some time ago and didn't succeed.
The alternative I chose is to put a config file into your Classpath (or jar file) with the relevant information.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Given that the environment is a fundamental aspect of the C language, it's not so farfetched to export it into java-land from the VM.  I'd really like to know why Sun deprecated it.

If you only need one or two settings like in your case, object's suggestion is the way to go.
Some platforms don't have environment variables.
Or maybe some allow multi-valued variables or some other variation.
Well, granted most embedded devices have no environment to speak of.  However, they don't usually have a console either.  That doesn't mean System.out should be deprecated.

I've written an Environment class that'll gather the environment from just about every non-embedded platform for which a VM is readily available.  Only older versions of Mac OS don't have an environment to speak of.

I'm just curious to hear Sun's rationale for making it go away.
Avatar of jernhung

ASKER

Hi,

This looks like something I can use in my case. I'll try to experiment with this a bit and see what I can come up with.

Thanks a lot folks!



Thanks for the points :)
I am also having a similar requirement.. I want to read the %USERNAME% Win XP environment Variable which wud allow the access to the application dependig on his role.

We are on Win XP clients, authenticated by a Novell Server (NDS), Replicated by Microsoft Active Directory. The users are already authenticated by these LDAPS and I just want to read the USERNAME variable in Win XP Using JSP 1.2.

Is there any way I can read this variable like others "request.getRemoteUser()". Any help will be appreciated.


TIA.

Raj.