因为一直以来使用tomcat和weblogic作为应用服务器为主,最近在升级新中间件的过程中遇到一个问题,我们的web前端应用现在升级是进行全量包升级的,因为现在的系统架构为前端和后端通过rpc框架交互的,后端使用java service wrapper进行管理,其组织架构允许我们在配置文件中随意设置lib目录(其实,早在三个月之前,笔者是非常不想使用它的),我们将三方类库和公司的框架类库以及应用类库分别放在不同的目录中进行管理,这样就可以仅仅升级应用jar包,框架和应用可以独立解耦的管理。
因为前端要提供视图层,所以还是用tomcat,但是在tomcat 6以及之后的版本中,和5.5以及之前的版本中,其类加载器架构发生了变化,去掉了原来的shared加载器,如下所示:
5.5架构
https://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
6.0以后架构:
https://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
注:https://www.mulesoft.com/tcat/tomcat-classpath和http://blog.csdn.net/andyelvis/article/details/6719996,有提及5.5以及之前的版本,6.0开始并无更新提及。
可见,已经没有了shared类加载器。虽然在catalina.properties中还有shares.folder参数,但该参数经测试并无作用。
#
#
# 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 "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=${catalina.home}/shared/lib,${catalina.home}/shared/lib/*.jar,${catalina.base}/shared/lib,${catalina.base}/shared/lib/*.jar
上述jar并没有被加载到应用中。
现在看来,如果一定要引用非标目录中的jar,只能加到tomcat/lib中的方式来解决。