如何将目录添加到特定 Tomcat 7 上下文的类路径?

How do I add a directory to the classpath of a specific Tomcat 7 context?

如何将目录添加到 classpath of the classloader assigned to a specific Tomcat 7 上下文?

我希望我的 Java Servlet 应用程序从类路径中的目录加载 warfile 外部的属性文件仅对该 servlet 可见。例如,主机 localhost 上的 servlet 上下文 /appA 应该加载 /etc/appA/application.properties (Linux) 或 D:\configuration\appA\application.properties (Windows) 而 servlet 上下文 /appB 在同一主机上不应在其类路径中包含 /etc/appA (Linux) 或 D:\configuration\appA\

如果要添加所有webapps的路径:

将目录路径名 /etc/appA 添加到 /conf/catalina.properties 文件的 common.loader 属性。

如果你想将路径添加到一个特定的 webapp:

在文件 $CATALINA_BASE/conf/Catalina/localhost/appA.xml 中,元素 <Context> 内,使用元素 <Loader> 和 class VirtualWebappLoader :

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/appA">
    <Loader className="org.apache.catalina.loader.VirtualWebappLoader"
              virtualClasspath="/etc/appA"/>
</Context>

参考文献:

VirtualClassLoader