Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java "user.dir" property - what exactly does it mean?

Tags:

java

I want to use user.dir dir as a base dir for my unit tests (that creates a lot of files). Is it correct that this property points to the current working directory (e.g. set by the 'cd' command)?

like image 851
johnny-b-goode Avatar asked Oct 18 '22 10:10

johnny-b-goode


People also ask

What are system properties in Java?

System properties include information about the current user, the current version of the Java runtime, and the character used to separate components of a file path name. Character that separates components of a file path.

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.

How do I change my user folder name?

You can use the usermod command to change the default home directory for a user. What this command does is edit the file /etc/passwd.

How do I set user folder in eclipse?

In Eclipse, the working directory defaults to the project directory. ( Project->Properties->Run/DebugSettings->Edit->Arguments tab, at the bottom of the page). Edit: Actually, the easiest way to get to it is Run->Open Run Dialog->Arguments tab.


1 Answers

It's the directory where java was run from, where you started the JVM. Does not have to be within the user's home directory. It can be anywhere where the user has permission to run java.

So if you cd into /somedir, then run your program, user.dir will be /somedir.

A different property, user.home, refers to the user directory. As in /Users/myuser or /home/myuser or C:\Users\myuser.

See here for a list of system properties and their descriptions.

like image 141
martinez314 Avatar answered Oct 20 '22 08:10

martinez314