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

十年热恋 提交于 2019-11-27 22:15:13

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

java -Djava.system.class.loader
    =com.test.YourCustomClassLoader com.test.YourMainClass

As Tomcat starts as a java application, you can set this parameter too, at the %TOMCAT_HOME%\bin\run.bat or $TOMCAT_HOME/bin/run.sh executable.

Edit for completion: If you set your classloader as de System class loader, it will be used to load Tomcat component classes, the different libraries, and your own classes. If you want your class loader to be used only for your application classes (including libraries and so), you should configure a Loader element for your context. The Loader element must be defined inside your Context element, wich can be defined at a context.xml file. More information:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!