aspose file tools*
The moose likes JBoss/WildFly and the fly likes System.getenv not working within JBoss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "System.getenv not working within JBoss" Watch "System.getenv not working within JBoss" New topic
Author

System.getenv not working within JBoss

Paul Smiley
Ranch Hand

Joined: Jun 02, 2000
Posts: 244
edit /etc/profile

adding lines

APP_HOME="/opt/app"
export APP_HOME

save file and close. Restart Linux (Fedora core 4) box to make this env variable visible to all shells.

Open a shell through Putty. Type 'echo APP_HOME' result is /opt/app . Bingo, right? No, the code in my ear file cannot see APP_HOME.

The code is:

private static String APP_HOME = System.getenv("APP_HOME");

However, inside JBoss under Linux this is always null. On Windows it works properly. And in a test standalone program in Linux this works fine.

A call to System.getenv() on Linux/JBoss returns the following keys:


XFILESEARCHPATH
LANG
PWD
_
SHLVL
JBOSS_HOME
USER
NLSPATH
HOME
LD_LIBRARY_PATH
TERM
SHELL
PATH
LOGNAME

However, if I do a 'echo $JBOSS_HOME' for instance within a shell, I get no result. And note that APP_HOME is not there in any form.

Anyone else experience this? Or am I doing something wrong?


Thanks,
Paul
[ June 13, 2007: Message edited by: Paul Smiley ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10112
    
165

The javadoc of System.getenv mentions that the method has been deprecated. It recommends using System.getProperty(String key). Try it out and see if it works:



[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10112
    
165

Also, more than being a JBoss specific problem, i guess you would see the same behaviour on a standalone Java program. Could you just try a simple java program which does the same - to figure out whether that works.
C Deepak
Greenhorn

Joined: Dec 12, 2007
Posts: 4
Hi,

I am also facing a similar problem with JBOSS 4.0.5GA on Linux.
I am using JDK 1.5 and hence using System.getenv is perfectly acceptable. My program is able to read the environment variable SETTINGS_CFG as a standalone program in linux and in Windows it works both as standalone and from within JBOSS. But on Linux with JBOSS it gives null.
Is it specific to JBOSS/Linux and any workarounds to solve this problem?

Please note that I cannot use System.getProperty as suggested in my context.
Appreciate your help.

thanks,
deepak
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10112
    
165

Originally posted by Deepak Chandra:


I am using JDK 1.5 and hence using System.getenv is perfectly acceptable.


The javadoc mentioned that this is deprecated in Java 1.4 which means you cant rely on this API even in JDK 1.5.


Originally posted by Deepak Chandra:
Is it specific to JBOSS/Linux and any workarounds to solve this problem?


I don't know whether using the System.getProperty API solved the issue for the original poster. So i dont know what's exactly causing this issue (add to it my lack of experience on using Linux).

Originally posted by Deepak Chandra:
Please note that I cannot use System.getProperty as suggested in my context.


Any reason why you can't use that?
 
 
subject: System.getenv not working within JBoss