Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.getProperty("user.dir") anomaly in Eclipse

Tags:

eclipse

In my current project settings, I have configured Eclipse to place the compiled .class files in the /bin directory.

My puzzle is that, when I run the application via the IDE and get it to print the current working directory (System.out.println(System.getProperty("user.dir")) I expect the console output to be /bin - instead the value printed is the projectRoot folder (without the /bin suffix).

If I were to navigate to the /bin folder directly, and execute my java class, the current working directory is printed as I expect it to be. What I would like is the Eclipse IDE to behave similarly.

Any ideas as to why I am observing this disparity? I have gone through many project build settings, but cannot seem to find anything that would cause this anomaly.

Kind regards, Dinuk

like image 278
Dinuk Avatar asked Dec 29 '25 07:12

Dinuk


1 Answers

In Eclipse, the working directory defaults to the project directory.
You can change this in the run properties
(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.
It's been a while since I used Eclipse.

From an example of Eclipse Setup New Project

alt text http://apps.sourceforge.net/mediawiki/sprite2d/nfs/project/s/sp/sprite2d/a/ae/EclipseNewProjectDebugArguments.jpg

like image 196
Michael Myers Avatar answered Jan 02 '26 16:01

Michael Myers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!