scarework
scarework

Reputation: 271

How to load class in system level from bootstrap level

I have a class that i defined in system.jar and i loaded it from classpatch. But in bootstrap.jar which i put in $JAVA_HOME/jre/lib/ext. I need to load a class which was defined in system.jar. How can i load it?

I known. When Tomcat is started, it creates a set of class loaders that are organized into the following parent-child relationships, where the parent class loader is above the child class loader:

  Bootstrap
      |
   System
      |
   Common
   /     \

Webapp1 Webapp2 ...

No have ways to load class with my idea?

Thanks,

Upvotes: 1

Views: 523

Answers (1)

Holger
Holger

Reputation: 298113

The class loader hierarchy is Bootstrap Loader → Extension Loader → Application Loader.

And, despite it’s name, ClassLoader.getSystemClassLoader() will return the application loader which will be the one which resolves classes using the supplied user CLASSPATH.

So from a class contained in bootstrap.jar (which will be loaded by the extension loader when placed in jre/lib/ext) you can use ClassLoader.getSystemClassLoader() .loadClass("class.within.your.classpath") to load the class from system.jar.

As a side note, in this typical setup, the expression ClassLoader.getSystemClassLoader().getParent()==MyClass.class.getClassLoader() will evaluate to true if MyClass has been loader by the extension loader.

Upvotes: 3

Related Questions