Re: help with understanding relative path problems



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.



.



Relevant Pages

  • Re: Giving an application a window icon in a sensible way
    ... already mentioned that bundling stuff in a jar is not a complication I ... You must be aware that Eclipse has a wizard for creating Jars. ... for resources in two places: in a jar with the app (where they'd be ... with the app; but then I need to set my class path on my development ...
    (comp.lang.java.programmer)
  • Re: help with understanding relative path problems
    ... I've developed and tested a java program in Eclipse. ... I then packed this program up into a jar file (which by the way is ... The problem is that all of the resources I've named in my program are ...
    (comp.lang.java.help)
  • help with understanding relative path problems
    ... I've developed and tested a java program in Eclipse. ... I then packed this program up into a jar file (which by the way is ... The problem is that all of the resources I've named in my program are ... will execute a program from? ...
    (comp.lang.java.help)
  • Re: Giving an application a window icon in a sensible way
    ... You don't have to tell the app where to find resources. ... Step 5, Fix the third party tool, because it was broken. ... resources that explains how exactly to make Eclipse hide any underlying ...
    (comp.lang.java.programmer)
  • Re: Giving an application a window icon in a sensible way
    ... newsgroup, spending lots of time and effort helping out people with their ... Did you say you were using Eclipse? ... then I have no further objections there. ... If I have more resources, ...
    (comp.lang.java.programmer)