Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between classpath and endorsed directory

Does anyone know what the difference is between adding an appropriate JAR-file (eg. Apache XALAN) to a JRE's endorsed directory and adding it to the application's classpath?

Is it possible to take a jar-file that can be added to the endorsed lib and instead add it to the classpath?

like image 278
Henrik Aasted Sørensen Avatar asked Dec 19 '08 08:12

Henrik Aasted Sørensen


People also ask

What is the difference between classpath and build path?

Build path is used by the compiler to resolve dependencies and build a project. Classpath is used during runtime when running a project in order to find necessary dependencies. Build path is configured on the Java Build Path property page of a project.

What is the use of path and classpath in Java?

PATH is used by CMD prompt to find binary files. CLASSPATH is used by the compiler and JVM to find library files.

What is classpath in web application?

The classpath is always set from a source outside the program itself. Separating this responsibility from the program allows the Java code to reference the classes and packages in an abstract manner, allowing the program to be configured for use on any system.

What is the importance of classpath in Java?

In Java, classes are loaded as needed while a program runs. The classpath is a list of locations (directory or JAR files) in which the JVM will look for classes to load. If a class to be loaded cannot be found, there will be an error and the program may abort.


1 Answers

Tecnically you probaly can do that, but the difference is that the jar files in the endorsed directory are loaded by the bootstrap classloader, which is probably not the same classloader as the one that loads your jars from the classpath.

There is a classic XML problem with the Xerces and Xalan XML implementations which are out in the endorsed directory. Because newer applications sometimes require newer versions of both libraries, and the classes have the same names, there is a classpath problem.

You can replace the Xerces and Xalan libraries in the endorsed dir (backup your old ones!) but that can possibly screw up other applications which use the same JRE installation.

I've even seen this problem within 1 application where one library depends on one version, and another library depends on another version of xerces. Very troublesome, and there's no "general approach" to this, or at least none that I found.

There are some interesting articles easily found by Google on this, try to find one which best matches your situation or problem.

like image 197
Rolf Avatar answered Sep 30 '22 17:09

Rolf