Return-Path: Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 20713 invoked from network); 5 Jul 2000 21:18:56 -0000 Received: from mail.netaxs.com (mail@207.8.186.26) by locus.apache.org with SMTP; 5 Jul 2000 21:18:56 -0000 Received: from [207.8.207.67] (ppp67.blackbox1-mfs.netaxs.com [207.8.207.67]) by mail.netaxs.com (8.8.7/8.8.5) with ESMTP id RAA11932 for ; Wed, 5 Jul 2000 17:18:52 -0400 (EDT) X-Sender: russgold@pop3.netaxs.com Message-Id: In-Reply-To: <3963A201.BDCC71D0@metamata.com> References: <85256913.000D9292.00@d54mta04.raleigh.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Wed, 5 Jul 2000 17:22:50 -0400 To: ant-dev@jakarta.apache.org From: Russell Gold Subject: Re: Working Directory Woes ... or Not ? X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N At 5:00 PM -0400 7/5/00, Louis Tribble wrote: >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). But isn't that what system properties are??? > >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? Because the current directory is used by the io package, which won't know about your CurrentDirectory class. As a result, certain programs need to run in specific directories to work properly. > >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. > I think it is likely that changing the property on the fly is not guaranteed to be safe; however, it should always be safe to establish it on the java command line: java -Duser.dir="/my/proper/directory" ProgramWhichCares as this setting will happen before any code copies it. The chief benefit of this would be to eliminate the need for the platform-specific batch files when starting a forked java task. This should work in any version of the JDK. ------------------------------------------------------------------------ Russell Gold | "... society is tradition and order russgold@acm.org (preferred) | and reverence, not a series of cheap russgold@netaxs.com | bargains between selfish interests." rgold@thesycamoregroup.com | - Poul Anderson, "Iron"