在Tomcat 8中将外部资源添加到类路径 [英] Adding external resources to class-path in Tomcat 8
问题描述
我有一个Tomcat应用程序需要引用应用程序外部的一些属性文件。通常这些存储在特定地方的本地计算机上,例如 C:\ PROJECT_NAME \\\\\\
。
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_NAME\conf\
.
在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.VirtaulWebappLoader"
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屋!