What is the correct way to replace files in Maven?

I have a Maven app with three different profiles listed below

<profiles> <profile> <id>dev</id> <properties> <profileVersion>DEV</profileVersion> <webXmlFolder>${id}</webXmlFolder> </properties> </profile> <profile> <id>test</id> <properties> <profileVersion>1.0.0-RC1</profileVersion> <webXmlFolder>${id}</webXmlFolder> </properties> </profile> <profile> <id>prod</id> <properties> <profileVersion>1.0.0-Final</profileVersion> <webXmlFolder>${id}</webXmlFolder> </properties> </profile> </profiles> 

And I have a Maven structure like this:

Src / main / configuration / default / WEB -INF / web.xml

SRC / Main / configuration / DEV / WEB-INF / web.xml

Src / main / configuration / test / WEB-INF / web.xml

Src / Main / configuration / Prod / WEB-INF / web.xml

SRC / Primary / WebApp / WEB-INF /

My task is to install the assigned web.xml in webapp / WEB-INF during construction, it depends on the given profile. If no profile is specified, then web.xml copies from the default folder.

I have a plugin but it does not work.

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>copy-prod-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <overwrite>true</overwrite> <outputDirectory>${project.build.outputDirectory}/classes/WEB-INF</outputDirectory> <resources> <resource> <directory>src/main/config/${webXmlfolder}/WEB-INF</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> 

Any ideas? I spent a lot of time on this problem and Im a bit confused.

+5
source share
1 answer

OK, now everything works. Here is my last code that works:

 <properties> <webXmlFolder>default</webXmlFolder> <profileVersion>defaultVersion</profileVersion> </properties> <profiles> <profile> <id>dev</id> <properties> <profileVersion>DEV</profileVersion> <webXmlFolder>dev</webXmlFolder> </properties> </profile> <profile> <id>test</id> <properties> <profileVersion>1.0.0-RC1</profileVersion> <webXmlFolder>test</webXmlFolder> </properties> </profile> <profile> <id>prod</id> <properties> <profileVersion>1.0.0-Final</profileVersion> <webXmlFolder>prod</webXmlFolder> </properties> </profile> </profiles> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>copy-web.xml</id> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <overwrite>true</overwrite> <outputDirectory>${basedir}/target/classes/WEB-INF</outputDirectory> <resources> <resource> <directory>src/main/config/${webXmlFolder}/WEB-INF</directory> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> 
+3
source

Source: https://habr.com/ru/post/1238385/


All Articles