从外部 war 读取 context.xml

read context.xml from outer war

我找到了几个类似的主题,比如从内部结构读取等,但是仍然没有解决我的问题。

项目结构:

我尝试了一些解决方案,例如:

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream input = classLoader.getResourceAsStream("META-INF/context.xml");

但是我没想到它会起作用,因为我认为我的 jar 在其结构中而不是在 war 中搜索此资源。

我需要 jar 项目war 项目[=] 中读取 context.xml 43=]。所以,jar 就像内部结构,而 war 是外部结构。可以吗?

使用 getResourceAsStream() 您可以访问类路径中的所有资源。 Web 应用程序的类路径由 WEB-INF/lib 下的每个 jar 和 WEB-INF/classes

下的每个文件组成

META-INF 不在类路径中。

请阅读问题:How to get resource from the context.xml file in tomcat webapp?