Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: System.getProperty("user.home") returns "?"

Tags:

java

kubuntu

I'm completely lost on this one: System.getProperty("user.home") and System.getProperty("user.name") returns a questionmark "?".

System-Specs: Kubuntu 9.04 Gnome 2.2.61 Java 1.5.0_16 

My testcase looks like that:

$ more Test.java class Test { public static void main( String[] args ) { System.out.println( System.getProperties() ); } } 

The result is (added line-breaks for better readability, replaced company name and own name):

$ javac Test.java $ java Test { java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/i386, java.vm.version=1.5.0_16-b02, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=:, java.vm.name=Java HotSpot(TM) Server VM, file.encoding.pkg=sun.io, sun.java.launcher=SUN_STANDARD, user.country=US, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/home/MYCOMPANY/myname/temp, java.runtime.version=1.5.0_16-b02, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/endorsed, os.arch=i386, java.io.tmpdir=/tmp, line.separator= , java.vm.specification.vendor=Sun Microsystems Inc., os.name=Linux, sun.jnu.encoding=UTF-8, java.library.path=/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/i386/server:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/i386:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/../lib/i386, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Server Compiler, os.version=2.6.28-15-generic, user.home=?, user.timezone=, java.awt.printerjob=sun.print.PSPrinterJob, file.encoding=UTF-8, java.specification.version=1.5, java.class.path=., user.name=?, java.vm.specification.version=1.0, java.home=/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre, sun.arch.data.model=32, user.language=en, java.specification.vendor=Sun Microsystems Inc., java.vm.info=mixed mode, java.version=1.5.0_16, java.ext.dirs=/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/ext, sun.boot.class.path=/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/rt.jar:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/i18n.jar:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/sunrsasign.jar:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/jsse.jar:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/jce.jar:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/lib/charsets.jar:/home/MYCOMPANY/myname/apps/jdk1.5.0_16/jre/classes, java.vendor=Sun Microsystems Inc., file.separator=/, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=gnome, sun.cpu.isalist= } 

Did someone ever experience that? Where is Java looking to find the user and home directory? I already checked the HOME environment variable which is set correctly.

like image 207
digitalbreed Avatar asked Oct 01 '09 11:10

digitalbreed


People also ask

What is the output of system getProperty user dir?

getProperty() is used to obtain the system property. This system property is specified by the key which is the parameter for the method. To obtain the current working directory, the key used is user. dir.

How does system getProperty work in Java?

The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java. lang. System Class. where key is the name of the System property.

What does system getProperty user dir return in Linux?

getProperty("user. dir") returns the "/home/user" (or "~") value instead of the folder that the jar is in? Essentially, it returns "user. home" instead of "user.

What is user home in Java?

For a multi-user operating system, there exists a file system directory for every user; this directory is known as the user's home directory. There are different ways to find the user home directory in Java.


2 Answers

It's a bit embarrassing but the solution was simply to use a 64-bit JDK on a 64-bit system. I copied everything from my old machine, which meant also a 32-bit JDK, and this was the problem. It worked as expected with a 64-bit runtime.

Sorry for bothering.

like image 124
digitalbreed Avatar answered Sep 19 '22 14:09

digitalbreed


A workaround, not a solution. You should be able to set it with by adding -Duser.home=$HOME as an argument.

java -Duser.home=$HOME Test 
like image 22
Billy Bob Bain Avatar answered Sep 21 '22 14:09

Billy Bob Bain