设为首页 收藏本站
查看: 346|回复: 0

[经验分享] tomcat common.loader&server.loader&shared.loader

[复制链接]

尚未签到

发表于 2017-1-29 09:36:42 | 显示全部楼层 |阅读模式
  ${catalina.home}/conf/catalina.properties文件可以用来配置tomcat内置classloader的load范围,一般默认情况如下


# List of comma-separated paths defining the contents of the "common"

# classloader. Prefixes should be used to define what is the repository type.

# Path may be relative to the CATALINA_HOME or CATALINA_BASE path or absolute.

# If left as blank,the JVM system loader will be used as Catalina's "common"

# loader.

# Examples:

#     "foo": Add this folder as a class repository

#     "foo/*.jar": Add all the JARs of the specified folder as class

#                  repositories

#     "foo/bar.jar": Add bar.jar as a class repository

common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar


#

# List of comma-separated paths defining the contents of the "server"

# classloader. Prefixes should be used to define what is the repository type.

# Path may be relative to the CATALINA_HOME or CATALINA_BASE path or absolute.

# If left as blank, the "common" loader will be used as Catalina's "server"

# loader.

# Examples:

#     "foo": Add this folder as a class repository

#     "foo/*.jar": Add all the JARs of the specified folder as class

#                  repositories

#     "foo/bar.jar": Add bar.jar as a class repository

server.loader=


#

# List of comma-separated paths defining the contents of the "shared"

# classloader. Prefixes should be used to define what is the repository type.

# Path may be relative to the CATALINA_BASE path or absolute. If left as blank,

# the "common" loader will be used as Catalina's "shared" loader.

# Examples:

#     "foo": Add this folder as a class repository

#     "foo/*.jar": Add all the JARs of the specified folder as class

#                  repositories

#     "foo/bar.jar": Add bar.jar as a class repository

# Please note that for single jars, e.g. bar.jar, you need the URL form

# starting with file:.

shared.loader=


下面两个方法都是copy自/Tomcat 6.0/java/org/apache/catalina/startup/Bootstrap.java,tomcat的启动类


    //下面三个classloader创建好,上面配置文件指定了load path,注意classpath下面并没有tomcat的自身类,所以 
  //appclassloader是加载不到的

 


    private void initClassLoaders() {
try {
commonLoader = createClassLoader("common", null);
if( commonLoader == null ) {
// no config file, default to this loader - we might be in a 'single' env.
commonLoader=this.getClass().getClassLoader();
}
catalinaLoader = createClassLoader("server", commonLoader);
sharedLoader = createClassLoader("shared", commonLoader);
} catch (Throwable t) {
log.error("Class loader creation threw exception", t);
System.exit(1);
}
}
   


public void init()
throws Exception
{
// Set Catalina path
setCatalinaHome();
setCatalinaBase();
initClassLoaders();
Thread.currentThread().setContextClassLoader(catalinaLoader);
//tomcat的启动类是在classpath下面的,由appclassloader加载,然后接下来的各个tomcat自身类由catalinaLoader加载,由于classloader的传递特性
//due to the classloader here, so the later classloader will be catalinaLoader
Class startupClass =
catalinaLoader.loadClass
("org.apache.catalina.startup.Catalina");
Object startupInstance = startupClass.newInstance();
Method method =
startupInstance.getClass().getMethod(methodName, paramTypes);
method.invoke(startupInstance, paramValues);
catalinaDaemon = startupInstance;
}
 

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-334781-1-1.html 上篇帖子: tomcat数据库连接池配置! 下篇帖子: tomcat配置文件server.xml详解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表