Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - package web.xml generated by Configuration Processor Plugin

In our web.xml, there is a fragment that is required only for development, it must not be present when the app is deployed into production. I'd like to use the Configuration Processor Plugin to remove this fragment when Maven has been invoked with production profile.

The transformation itself is easy, but what would be the best way to package this generated web.xml to WAR file? I'm outputting the transformed web.xml to directory target/generated-sources. When the production profile is active, I'd like Maven to use this web.xml instead the one in the src directory. If this profile is not active, then the standard location should be used.

like image 370
prasopes Avatar asked Jun 12 '26 20:06

prasopes


1 Answers

I'd create a property, say, webXml.path and configure Maven the following way:

<properties>
  <webXml.path>src/main/webapp/WEB-INF/web.xml</webXml.path>
</properties
...
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <configuration>
        <webXml>${webXml.path}</webXml>
      </configuration>
    </plugin>
  </plugins>
</build>
...
<profiles>
  <profile>
    <id>prod</id>
    <properties>
      <webXml.path>target/generated-sources/web.xml</webXml.path>
    </properties>
  </profile>
</profiles>
like image 133
Andrew Logvinov Avatar answered Jun 18 '26 00:06

Andrew Logvinov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!