ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Louis Tribble <>
Subject Re: Working Directory Woes ... or Not ?
Date Wed, 05 Jul 2000 21:00:49 GMT
Russell Gold wrote:
> At 10:33 PM -0400 7/4/00, Peter Donald wrote:
> >Hi,
> >
> >Can someone point out where my stupidity lies here :P. I was under the
> >impression that working directory was impossible to set in java. However
> >recently I have been playing with
> >System.setProperty("user.dir","someotherdirectory") and everything seems to
> >work !!! hmmm The only problems occured when I used relative paths. So what
> >I did at the begining of my program was resolve any relative paths to
> >absolute paths. This means you have to resolve some system properties (ie
> >"java.class.path") and also some internal paths inside the program.

Some comments: 

1. Doing this with user.dir is effectively using system properties
as a global constant pool (three whacks with a ruler).

2. A lot of code, including JDK code, puts the value of the property in a 
static initializer, so you which value you get may depend on which class 
loads first.

3. Given 1 and 2, if current directory redirection is really required, 
why  not create a CurrentDirectory singleton to make the magic explicit, 
documented, and predictable?

4. exec is unaffected (this is where the current directory has usually
mattered to me). I understand JDK 1.3 adds a way to set the current
directory when exec-ing.

5. Never having seen JDK source, I also can't rule out some bits of
native library code (either JDK or extensions) getting the value from a 
source unaffected by setting the user.dir property.

Hmmm, I hope the above doesn't sound too much like I got up on the
wrong side of the bed today...

Louis Tribble

Louis Tribble                               
Metamata, Inc.                         
Tools for serious Java developers.                       +1 510 796 0915

View raw message