bsd5tu1 wrote:
> baseFile = new File(".");
That line sets baseFile to the current RUNTIME directory, i.e. the
directory named by the property "user.dir". This has nothing to do with
how or when the jar was created, nor what the contents of the jar is.
One part of the problem seems to be that the current directory doesn't
necessarily match the directory where the jar is located. The other part
of the problem is that the contents of a jar is not the same as a file or
directory in the file-system. File objects are ONLY file-system objects,
not jar resources.
By analogy, contrast the contents of a tar or zip archive with a directory
containing the originals of the archived files. The two are not
interchangeable.
>Maybe I misunderstand the capabilities of "Jar" but I was under the
>impression that a jar command useage like this:
>
>jar cvmf manifest ImageViewer.jar *.class Images
>
>would have made the ImageViewer jar reference the Images directory with
>respect to the location of the jar file.
Nope. What that 'jar' command does is COPY the contents of the Images
directory INTO the jar. There is no "reference" involved. You get copies
in the jar, not references to an external directory. By analogy, 'jar' is
making a copy like 'cp' makes a copy, not a reference like 'ln -s' makes a
reference (symlink).
To refer to jar resources, you have to use the getResource() family of
methods in Class and ClassLoader.
> If we move the jar file created
>above to some other directory where the Images subdirectory doesn't exist,
>the program will start up but then throw a null pointer exception when it
>tries to load an image, EVEN THOUGH THE "Images" directory has been tarred
>up and put into the jar.
You have to use getResource() or one of its friends in order access jar
resources.
>This needs to be done in a platform independent way, so using JarBundler
>isn't an option (I don't think)
getResource() is platform independent. JarBundler should work fine
(depending on if you mean the Apple utility or the Ant task).
However, I can't tell if your presumed "./Images" directory is for
read-only images, or whether you intend users to add and remove images. If
the former, then jar-resources suffice. If the latter, you have to
determine where the jar itself is located, and then build a pathname or
File relative to that in order to get a true jar-relative "Images"
directory.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden
This email sent to email@hidden