tags:

views:

493

answers:

3

Hi All :
I have used a method "System.getenv();" to get a value of user defined environment variable in jar application. I have made the jar application to run from window service. But when i try to start the service, it is not getting user defined environment variable's value and showing null pointer exception. I have tried with System variable name in "System.getenv("JAVA_HOME");" method, its working fine by getting the respective value. What is the error with User variable in envirinment variables. Should i do anything in the code?

+1  A: 

Windows services run on behalf of the system, not a particular user. I believe you can configure the service to run as a specific user, at which point you may get the relevant environment variable - but it would be a lot better to configure the application with a properties file or something similar.

Jon Skeet
+1  A: 
VonC
A: 

A windows service gets the user environment of the user the service runs as.

Peter Lawrey