Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
How to determine the runtime application path
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to determine the runtime application path



To date I have been developing applications which run from a server so
apologies if my questions about desktop applications seem rather basic to
all of you who do desktop application development. TIA for the help, peace
and understanding ;I

I have started with a VERY basic desktop application which at the moment is
simply a directory which contains a .jar file and another directory for my
shared libraries. Just getting my feet wet with the Mac way of doing shared
libraries has been interesting and I realize that a proper Mac application
would use the frameworks paradigm .... etc. But I wanted to just get a
simple, basic java feel for what I needed to do so for the moment I am using
a jar file and a manifest. There is no *installer* for any of the supported
platforms; the idea being you just unzip the file, read the README and then
run the application from the mouse or from the command line.

As I mentioned I need to load shared libaries which are in a subdirectory:
Test (directory)
| - Test.jar (jar file)
| - resources/ (directory of shared libraries)

Loading the shared libraries with System.load("path-to-library-file") works
as advertised. The problem is finding the absolute path to the directory!

There is no installer for the application and I make no requirements where
the user can put the Test application directory. The only requirement is
that the contents of the application can always be found from the Test
directory.

In order to find the absolute path to the application I thought would be
simple using ...ClassLoader.getResource("Test") or ...("Test.jar") but both
these return null. Searching Google site:java.sun.com, etc. hasn't shed
any light on how I can find from where in the file system the application
was launched.

The only way I have found is to create a fictitious File(""); and get its
absolute path. This seems to work for all cases (dbl-click, java -jar and
java -cp..).

Is this the correct (best practice) means of getting the application
location within the file system? Seems an a completely non-intuitive if not
odd way of doing it.

tks,

java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-69.1)
Java HotSpot(TM) Client VM (build 1.4.1_01-24, mixed mode)

Steven
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Do not post admin requests to the list. They will be ignored.




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.