Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

System.getProperty("user.name") not working without /etc/passwd, CentOS 4.3

843798Oct 15 2007 — edited Mar 21 2008
Dear all,

I'm having trouble getting the system property user.name (which we need in our ant scripts) on our CentOS box. :(


When running the program below thru

java dumpproperties2

it prints "user.name='?'" on our CentOS 4.3. On win32 it works. It turns out that if you add the account corresponding to the EUID to /etc/passwd it works correctly. However, we don't use passwd authentication but an enterprise wide LDAP-system. Our /etc/nsswitch.conf says:

passwd: files ldap

One work around is to replace the java executable with a script that does
/path/to/jdk/bin/java -Duser.name=$USER -Duser.home=$HOME $@

Used jdk is j2se 1.5.0_13 Linux 32-bit.

Some questions for the experts:

1) Is there any other way?

2) Is it a known issue that Linux versions of the jdk just looks in /etc/passwd to map uid to user name (and home dir) instead of doing what the rest of the system, like whoami, does? I haven't found anything in either the readme or installation instructions, nor in the bug db.

Br, Jesper Tr�g�rdh
public class dumpproperties2 {

    public static void main(String[] args) {
	String s = System.getProperty("user.name");
	System.out.println("user.name='" + s + "'");
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 18 2008
Added on Oct 15 2007
3 comments
210 views