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

Java

Java Problem Overview


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)?

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

user.dir is the "User working directory" according to the Java Tutorial, System Properties

Solution 3 - Java

Typically this is the directory where your app (java) was started (working dir). "Typically" because it can be changed, eg when you run an app with Runtime.exec(String[] cmdarray, String[] envp, File dir)

Solution 4 - Java

System.getProperty("user.dir") fetches the directory or path of the workspace for the current project

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjohnny-b-goodeView Question on Stackoverflow
Solution 1 - Javamartinez314View Answer on Stackoverflow
Solution 2 - JavaMark RotteveelView Answer on Stackoverflow
Solution 3 - JavaEvgeniy DorofeevView Answer on Stackoverflow
Solution 4 - Javauser7123229View Answer on Stackoverflow