Deploying a War File to Tomcat Root With Maven pom.xml

14,539

Solution 1

I believe you can leave the war named client.war if you'd like. Then configure the tomcat6 plugin, setting the path like this:

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat6-maven-plugin</artifactId>
  <version>2.0-beta-1</version>
      <!-- put the configuration in an execution if you want to... -->
      <configuration>
        <path>/</path>
        <warFile>${project.build.directory}/client.war</warFile>
        <!-- other config options here -->
      </configuration>
</plugin>

I haven't used tomcat7 version of the plugin, but I'm guessing it's similar.

Solution 2

Since you're using the combination of eclipse, tomcat, and maven, I'm going to make the guess that the m2e-wtp plugin is in use here. There's a FAQ that addresses this. This also shows though how to change your context root in a maven specific way (using the war plugin for specifying a finalName for the war) which results in a correctly named war file (such as ROOT.war as mentioned in other answers.

Share:
14,539
Dominik
Author by

Dominik

Updated on June 04, 2022

Comments

  • Dominik
    Dominik almost 2 years

    Assuming the following pom.xml maven would build a client.war file which when deployed to Tomcat will have the URL www.server.com:8080/client/

    What would one have to change so the application can be reached at the server root www.server.com:8080/?

    <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>...</groupId>
        <artifactId>client</artifactId>
        <packaging>war</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>...</name>
        <url>http://maven.apache.org</url>
        <build>
            <resources>
                <resource>
                    <directory>target/generated-resources</directory>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
            <plugins>
                ...
            </plugins>
            <finalName>client</finalName>
        </build>
    ...
    </project>