When using an external jar by giving the absolute path to it in the
Class-Path header, the working directory for the classes in the
external jar is still the one for the jar package, is this correct?
The working directory is controlled by the host operating system and is
not affected by the classpath. Generally, it will be the working
directory that was in effect when you launched the JVM.
I have a java application which needs some external jar-files
(openoffice). These external jar files do one tricky thing: they looks
for some native libraries relative to their own location.
The external jar-files are found and the classes are loaded, BUT when
they try to locate the native libraries they fail! It seems that they
can't create an absolute path the the library.
Is this behavior correct?
The OpenOffice.org code is determining the location of the native
libraries on its own, and it sounds like that is where the problem is.
Whether or not it is the *correct* behavior really on the design
specifications and documentation for OpenOffice.
In any case, it looks like the algorithm used in OpenOffice to find the
native libraries is lacking. My guess is that it is using the classpath
(either the "java.class.path" System property or the URL list from the
AppClassLoader) to determine the directories to look in. However, paths
listed in the JAR manifest "Class-Path" attribute would not be included
in either.
I think a better approach for OpenOffice to use would be to get the path
from one of the classes in the OpenOffice JAR file. This can be done with
the following expression:
XXX.class.getProtectionDomain().getCodeSource().getLocation();
The above methods can return null, so the code would need to check the
return values before referencing them, but that is pretty much what would
be needed.
Depending on how the OpenOffice code is written, it may also be using the
default mechanism for locating libraries, System.loadLibrary(). If that
is the case, then the default search path would be the value of the System
property "java.library.path". You might try setting this to point to the
directory that contains the native libraries. Note that you cannot do
this programmatically, since the value will be processed by the JVM setup
code. You need to specify this on the Java launcher command line.