我在Tomcat 7中有Custom SharedClassLoader来加载共享库jar,这是由tomcat中的不同应用程序使用的。我们迁移到Tomcat 9,现在它无法运行。如何在tomcat 9中实现相同的功能。
在Tomcat 9中,它希望传递资源。我没有找到任何关于如何填充资源的示例代码。
我尝试过如下
public CustomSharedClassLoader(ClassLoader parent) throws Exception {
super(parent);
//The below three lines are added by me to work for Tomcat 9.
StandardRoot standardRoot = new StandardRoot();
standardRoot.addPreResources(new DirResourceSet());
setResources(standardRoot);
// End for tomcat 9 changes.
for (URL urlForJars : getClassPath(SHARED_LIB)) {
addURL(urlForJars);
}
start();
}
它没用。
public class CustomSharedClassLoader extends WebappClassLoader{
//Which takes shared folder libarary, it returns those classes.
}
您可以在catalina.properties中添加共享类
shared.loader=${catalina.home}/shared/classes,${catalina.home}/shared/*.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:.