0

I am using System.getProperty("user.dir") as the entry point (absolute path) in which any other file (and directory) traversal is relative with respect to the entry point.

The user.dir property has different values whether the program is invoked from the command line, or by the IDE (as expected).

What is the best practice to insure that the user.dir property will be "independent" in the execution environment?

Update: if you are using Eclipse for your IDE, check System.getProperty("user.dir") anomaly in Eclipse

Community
  • 1
  • 1
Mr.
  • 9,429
  • 13
  • 58
  • 82

1 Answers1

2

The whole point of the user.dir and similar properties is, that it is dependent on the execution environment.

So the answer would be: don't

What you can do though in eclipse is to edit the run configuration to use a working directory that fits your needs. This will be available in other IDEs as well I guess.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • so implicitly it means that one which develops using IDE must expect a different behavior when the program is invoked from the command line? – Mr. Oct 14 '12 at 19:03
  • absolut. Note that eclipse (and I guess every IDE) lets you configure the directory used as user.dir / working directory. – Jens Schauder Oct 14 '12 at 19:26