3

I have a problem with maven. i'm alredy using tomcat7-maven-plugin to deploy my war into a tomcat and it works great.

But now I would like to change a file into my generated war before to send it to servlet container. Is it possible? Particularly I want to change default web.xml with another one.

I've already tried a maven-resources-plugin as showed below:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.4.2</version>
  <executions>
    <execution>
        <id>default-copy-resources</id>
        <phase>package</phase>
        <goals>
            <goal>copy-resources</goal>
        </goals>
        <configuration>
                <overwrite>true</overwrite>
                <outputDirectory>${project.build.directory}/${project.artifactId}/WEB-INF/</outputDirectory>
                <resources>
                    <resource>
                        <directory>${project.basedir}/src/main/webapp/ext/WEB-INF</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

but this plugin replace web.xml just on target WEB-INF folder, nothing will be changed into war file. Someone can help me to find the right plugin to achive my purpose?

UPDATE:

I resolved using this: https://stackoverflow.com/a/3298876/2148530

Community
  • 1
  • 1
giaffa86
  • 708
  • 1
  • 9
  • 22
  • I'm not quite sure what you are trying to achieve? If you want to use a (possibly faulty) web.xml you can always put it in `src/main/webapp/WEB-INF` in the standard directory layout. – Mikkel Løkke Jan 23 '14 at 13:58
  • 2
    Do you want to change it for specific builds only? That can be done using maven profiles. But what do you want to achieve? To change the whole web.xml or have some of their attributes with different values? – Aritz Jan 23 '14 at 14:30
  • I've already have a `web.xml` in `src/main/webapp/WEB-INF` but i would replace it with another one during build and deploy. – giaffa86 Jan 23 '14 at 15:39
  • Consider that the right phase it isn't package but `tomcat7:deploy`. So when I launch `mvn tomcat7:deploy`. I would like to change web.xml. But your second option could be ok. The replacing `web.xml` is similar to original one, it is slightly different. – giaffa86 Jan 23 '14 at 15:41

2 Answers2

2

You can define your profile(in your pom.xml) within it you override the maven.war.webxml property :

<properties>
    <maven.war.webxml>path/to/your/custom/web.xml</maven.war.webxml>
</properties>
  • This solution is very powerful when combined with maven profiles. In that way, it is possible to define one different web.xml for each profile. – sogeking Dec 13 '16 at 09:29
0

Solution (not mine), taken from question Maven: Customize web.xml of web-app project with Maven War Plugin and webXml parameter.

webXml The path to the web.xml file to use.

Sample usage

<profiles>
    <profile>
        <id>tomcat</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <webXml>${project.basedir}/src/main/webapp/ext/WEB-INF/web.xml</webXml>
                    </configuration>
                </plugin>
                 ...
Community
  • 1
  • 1
MariuszS
  • 30,646
  • 12
  • 114
  • 155