java - How to set my custom class loader to be the default? -


I'm trying to practice myself with a custom class loader, and I have a few questions at the global level Is there a way to point out JVM to use my custom class loader? For example, I ran small apps under Tomcat 6. The servlet is managed by the container, where should I set my class loader? In addition, the webpage uses some third-party jar, can I control the sections that load those jars?

In the case of the standalone app, will the above answers be different?

Thank you!

You can set the system default class loader as a JVM argument:

Tomcat starts as a Java application, such as
  java -dajava.system.class.loader = com.test.YourCustomClassLoader com.test.YourMainClass  

you This parameter can also be set, executable on % TOMCAT_HOME% \ bin \ run.bat or $ TOMCAT_HOME / bin / run.sh .

Edit to complete: If you set your classloader to be a system class loader, then this tomcock loads components, various libraries, and their classes Will be used to If you want your class loader to be used only for your app classes (including libraries), then you should configure a loader element for your reference. Loader element should be in your context < / Code> element, which can be defined on the context.xml file. More information:

  • : Defines how classloader works in a tomcat.
  • : How to define context element
  • : For your own context your custom loader element.

Comments