Re: help with understanding relative path problems
- From: Mark Space <markspace@xxxxxxxxxxxxxx>
- Date: Fri, 15 Aug 2008 16:48:19 -0700
darren wrote:
Hi everybody
I've developed and tested a java program in Eclipse. In it, I name a
few resources that the program needs like so:
File template = new File("Resources/myTemplate")
I then packed this program up into a jar file (which by the way is
overly complicated in Eclipse it seems). Anyways, I moved this jar
file, then call it from a toolchain. Here is the call:
java -jar ../tools/myJar.jar arg1 arg2
The problem is that all of the resources I've named in my program are
being resolved relative to where the program is being executed,
Yup. As far as I know, every OS on the planet does this.
instead of being relative to where the jar fie is living. this seems
counter intutitive to me. How does the programmer know where a user
will execute a program from? I can't even use an absolute filename
You don't know. All those programs that ask you to set an environment variable INTSALLED_PROG_HOME=c:\usr\bin\prog
They do it so they can find their installed directory. Consider having the installer add a property to the .jar that is the default directory for the file. Java unfortunately does not provide this on the command line. Alternately, you can just have your tool chain CD to the correct directory, since it seems to know where the program is:
(cd ..\toos; java -jar myJar arg1 arg2)
That's bash shell, I think. Check carefully under Windows. (Check carefully under Unix too for that matter.) Or set an environment variable or pass the required directory on the command line yourself.
.
- References:
- help with understanding relative path problems
- From: darren
- help with understanding relative path problems
- Prev by Date: help with understanding relative path problems
- Next by Date: Friendster + YouTube +MySpace+ Date
- Previous by thread: help with understanding relative path problems
- Next by thread: Re: help with understanding relative path problems
- Index(es):
Relevant Pages
|