Thursday, April 28, 2011

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

Hello,

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

From stackoverflow
  • 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

    Michael Myers : And if I were VonC, I'd add an appropriate screenshot.
    Dinuk : @mmyers: Thank you so much - I already spent 5 minutes trying to figure what could be causing this, and was afraid I would end up spending the best part of an hour looking for a hidden config setting. Thank you for the prompt response - I'll try to post a more interesting question next time :-)
    VonC : @mmyers: all right, all right, just gimme a minute ;) +1, by the way
    Michael Myers : No, really, that's not the way I meant it. I meant that if I were you, and if I (being you) were posting an answer to this question, I (being you) would include a picture. I didn't mean that if I were you, I (being you) would go and add a picture to mmyers's post. Thanks for adding it, though. :)
    Michael Myers : (I'm assuming it illustrates what I said; flickr is blocked by the proxy server here.)
    VonC : @mmyers: yes, I figured you meant it the way you just described. I just wanted to tease you a little bit, hence my tongue-in-cheek comment ;)
    VonC : darn, flick blocked (just like for me at work, except I am posting this from home). I will check if I find a more accessible illustration.
    VonC : ... and done (feel free to revert any change you might find inappropriate or not in the spirit of your original answer)
    Michael Myers : Looks good to me, thanks!

0 comments:

Post a Comment