简体   繁体   中英

Replace value in my Web.xml with maven

I have in my Web.xml a value

<display-name> MyApp version @minorversion@- Pré prod </display-name>

I want to know if It's possible to read a properties file with maven to replace the value in my Web.xml when I want to compile or package..?

You can use the maven-replacer-plugin

              <plugin>
                    <groupId>com.google.code.maven-replacer-plugin</groupId>
                    <artifactId>replacer</artifactId>
                    <version>1.5.3</version>
                    <executions>
                        <execution>
                            <id>REPLACE</id>
                            <goals>
                                <goal>replace</goal>
                            </goals>
                            <phase>{Phase to execute in}</phase>
                          <configuration>
                                <file>${Path to file to replace}</file>
                                <regex>true</regex>
                                <token>${Regex to match in file}</token>
                                <value>${New Value to Replace matched}</value>
                                <regexFlags>
                                    <regexFlag>MULTILINE</regexFlag>
                                    <regexFlag>DOTALL</regexFlag>
                                </regexFlags>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
  1. Add src\\main\\resources\\conf.properties:

     minorversion=1.0.0.0 
  2. pom.xml

      <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <resourceEncoding>${project.build.sourceEncoding}</resourceEncoding> <webResources> <resource> <filtering>true</filtering> <directory>src/main/webapp</directory> <includes> <include>**/web.xml</include> </includes> </resource> </webResources> <filters> <filter>src/main/resources/conf.properties</filter> </filters> </configuration> </plugin> 
  3. web.xml

     ... @minorversion@ 

    or

     ${minorversion} ... 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM