Resolving JAR dependencies from within / usr / share / java

Can someone explain how the JAR files and the Java class loader use /usr/share/java? Is this a special directory in which the JVM will automatically load the JAR and search for classes, but not others?

For example, if I have x.jarone that depends on y.jar. If both banks are in /usr/share/java, a dependency,, y.jaris detected at boot x.jar. But when loading x.jarfrom any other directory, I must explicitly put y.jarin the classpath, even if it is still in the same directory as x.jar. Why is this?

Is there a way to make other directories behave like /usr/share/java?

+3
source share
2 answers

Depending on your distribution, it /usr/share/javamay be among the directories specified in the system property java.ext.dirs. The article Architecture of the expansion mechanism explains in more detail. The location of these extensions depends on the platform and version, as indicated in the Installed extensions .

Application: you can test the property on your platform with the following line of code:

System.out.println(System.getProperty("java.ext.dirs"));

Application: if you look, it /usr/share/javadoes not appear in any system property; the effect may be due to the property of the Class-Pathcorresponding JARs manifest. Using this handy utility , you can study 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/
+2

.

/usr/share/java , , Debian jars . , classpath , java, .

+2

Source: https://habr.com/ru/post/1791613/


All Articles