将外部资源添加到 Tomcat 8 中的类路径 [英] Adding external resources to class-path in Tomcat 8
问题描述
我有一个 Tomcat 应用程序,它需要引用应用程序外部的一些属性文件.通常,这些存储在本地计算机上的特定位置,例如 C:PROJECT_NAMEconf
.
I have a Tomcat application which needs to reference some properties files that are external to the app. Generally these are stored on a local machine at a specific place like C:PROJECT_NAMEconf
.
在 Tomcat 7 中,这可以通过在 /META-INF/
中放置一个 context.xml
文件来实现,该文件使用了 VirtualWebappLoader
将此位置添加到应用程序类路径中,如下所示:
In Tomcat 7 this was achievable by placing a context.xml
file inside of /META-INF/
which used a VirtualWebappLoader
to essentially add this location to the application classpath as follows:
<Context>
<Loader className="org.apache.catalina.loader.VirtualWebappLoader"
virtualClasspath="/PROJECT_NAME/conf"
searchVirtualFirst="true" />
</Context>
如何在 Tomcat 8 中实现同样的功能?
How do I achieve this same thing in Tomcat 8?
推荐答案
Tomcat 8 迁移指南,它将指导您使用 资源配置
特别是,您将创建一个 WebResourceRoot 对象,在其描述中包含以下文本.
In particular, you will be creating a WebResourceRoot object which contains the following text in its description.
VirtualWebappLoader - 替换为映射到 WEB-INF/lib 和 WEB-INF/classes 的前置和后置资源
VirtualWebappLoader - Replaced by Pre- and Post-Resources mapped to WEB-INF/lib and WEB-INF/classes
您的新 context.xml 将类似于以下内容:
Your new context.xml will look something like the following:
<Context>
<Resources className="org.apache.catalina.webresources.StandardRoot">
<PreResources className="org.apache.catalina.webresources.DirResourceSet"
base="C:\PROJECT_NAME\conf"
internalPath="/"
webAppMount="/WEB-INF/classes" />
</Resources>
</Context>
这篇关于将外部资源添加到 Tomcat 8 中的类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!