Can someone please explain how JAR files and the Java class loader make use of /usr/share/java
? Is this a special directory that the JVM will perform automatic JAR loading and class lookups in, but no other?
For example, if I have x.jar
that depends on y.jar
. If both jars are in/usr/share/java
the dependency, y.jar
, is found when loading x.jar
. But when loading x.jar
from any other directory, I have to explicitly put y.jar
on the classpath, even when it is still in the same directory as x.jar
. Why is this?
Is there any way to make other directories behave like /usr/share/java
?
Advertisement
Answer
Depending on your distribution, /usr/share/java
may be among the directories specified in the system property java.ext.dirs
. The article Extension Mechanism Architecture explains in more detail. The location of such extensions is platform and version dependent, as mentioned in Installed Extensions.
Addendum: You can examine the property on your platform with the following line of code:
System.out.println(System.getProperty("java.ext.dirs"));
Addendum: Looking closer, /usr/share/java
does not appear in any system property; the effect may be due to the Class-Path
property of the relevant JARs’ manifest. Using this convenient utility, it’s possible to examine them.
/usr/share/java/ant-bootstrap.jar Class-Path: ant.jar xml-apis.jar xercesImpl.jar xalan.jar /usr/share/java/openoffice/java_uno.jar Class-Path: jurt.jar ridl.jar ../../lib/ ../bin/ /usr/share/java/openoffice/juh.jar Class-Path: ridl.jar jurt.jar ../../lib/ ../bin/ /usr/share/java/openoffice/jurt.jar Class-Path: ridl.jar unoloader.jar ../../lib/ ../bin/