Re: Problem executing Java programs from a Nautilus window?
On 15/03/11 19:10, Knute Johnson wrote:
On 03/15/2011 05:14 AM, Eric Sosman wrote:
On 3/15/2011 5:58 AM, Jukka Lahtinen wrote:
Knute Johnson<nospam@knutejohnson.com> writes:
[...]
Does everybody just put their data files in their home directories?
User files belong to the user's home directory, preferably in some
subdirectory under it. Quite often users don't even have (or need) write
permissions anywhere else. And with the default permission settings, in
the (subdirectories of the) home directory they are safe from other,
possibly hostile, users.
Also consider using command-line parameters and/or environment
variables to designate interesting files and directories, just as
you use them for things like "The database is on too.faraway.com,
listening to port 9876."
Makes sense what you and Jukka said. The one thing I'm really curious
about now is how does it find the library .jar file that is in the same
directory as the app that is running from a different directory? This
is starting to get really confusing.
Java does that, provided the Class-path: in the manifest of the main jar
uses relative paths. The base path the classloader uses to the locate
dependent jars is the location of that jar. For example, if you run the
jar /home/me/Java/jars/someProgram.jar, and the manifest contains
"Class-path: lib/some-lib.jar", then java will locate the jar file
/home/me/java/jars/lib/some-lib.jar.
You can use this from the command-line also, to run a jar located
anywhere on the filesystem. The main jar and its libraries can be
installed wherever you wish without having to modify the manifest. You
just need to maintain the relative paths of the main jar and its libraries.
If you want to locate other files in the same directory as the jar
itself you may be able to interrogate the classloader. It's not
something I've done, so don't know if it's possible.
If I run a jar which dumps all the system properties I can see one
called java.class.path, which contains the full path to the executable
jar. From this you could determine the directory containing the jar, to
access other files in that directory.
--
Nigel Wade