【问题标题】:read context.xml from outer war从外部战争中读取 context.xml
【发布时间】:2016-07-27 11:07:56
【问题描述】:

我发现了几个类似的主题,比如从内部结构阅读等,但它仍然不能解决我的问题。

项目结构:

  • 整个项目 -> 战争,其中有:

    几个 jar 连接为依赖项 在 pom.xml 中;

    META-INF 文件夹中的context.xml,我需要从其中一个jar 中读取。

  • 其中的一部分 -> jar,它是war的pom.xml中的依赖项

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

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

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

我需要 jar 项目war 项目 中读取 context.xml。所以,jar 是内部结构,war 是外部结构。有可能吗?

【问题讨论】:

    标签: java jar war


    【解决方案1】:

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

    META-INF 不在类路径中。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-05
      • 2020-02-11
      • 2022-11-10
      • 1970-01-01
      • 2013-06-24
      • 1970-01-01
      • 2014-09-23
      相关资源
      最近更新 更多