开发者

How do I filter overlayed WAR resources when building a WAR with Maven?

开发者 https://www.devze.com 2023-02-19 18:57 出处:网络
I have two WARS: base-overlay example-app base-overlay has XML config files in src/main/webapp/WEB-INF/spring/*.xml.In those XML config files, I have parameters that need to be filtered when build

I have two WARS:

  1. base-overlay
  2. example-app

base-overlay has XML config files in src/main/webapp/WEB-INF/spring/*.xml. In those XML config files, I have parameters that need to be filtered when building the example-app WAR, which depends on base-overlay to be its overlay. For example, base-overlay/src/main/webapp/WEB-INF/spring/app-context.xml has ${data.url} in it. When packaging the example-app WAR, I've set the POM property <data.url>http://example.com:1234</data.url> to replace base-overlay's ${data.url}.

When I configure the mave开发者_如何学Cn-war-plugin to filter this file, I had to give it a directory of target/war/work/com.example/base-overlay/WEB-INF/spring just to find the app-config.xml file to filter before adding it to the newly packaged example-app WAR. This seems like a hack, and also doesn't work when testing with Jetty, as the WAR isn't created and filtered.

Furthermore, the POM's <build/> element has a <resources/> element, but I couldn't get that to work.

How do I filter the overlay resources when compiling?


To resolve this issue, I moved all XML resources (Spring) to the appropriate Maven resource directory ${basedir}\src\main\resources\ and then added that to the POM in the <build/> element like:

<resources>
    <resource>
        <directory>${basedir}/src/main/resources/</directory>
        <filtering>true</filtering>
    </resource>
</resources>

I included the common XML resources that don't need to be filtered the in the base-overlay WAR. In each application that uses the base-overlay WAR, I added an XML file named filtered-resources.xml that is filtered each time the application WAR is packaged and assembled by Jetty.

0

精彩评论

暂无评论...
验证码 换一张
取 消