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

前端 未结 3 649
没有蜡笔的小新
没有蜡笔的小新 2021-01-15 15:03

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

相关标签:
3条回答
  • 2021-01-15 15:21

    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.

    0 讨论(0)
  • 2021-01-15 15:28

    Maven war plugin (which is defined on super-pom by default) will only generate a war file. It's up to you to set up your app on Tomcat. If you want to add the "deploy to a container" to your maven build, go with Tomcat Maven Plugin or Cargo Maven Plugin.

    What you want has nothing to do with Maven, actually. Setting your war name to ROOT.war should do it (<finalName>ROOT</finalName> on your build section), but if you want to add your context.xml to the war file, you could do something like (assuming src/main/webapp is your webapp folder defined by maven):

    `<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    
    <artifactId>maven-war-plugin</artifactId>  
            <configuration>  
              <webResources>  
                <webResource>  
                  <directory>${basedir}/src/main/webapp/META-INF</directory>  
                  <includes>  
                    <include>context.xml</include>  
                  </includes>  
                  <targetPath>META-INF</targetPath>  
                  <filtering>true</filtering>  
                </webResource>  
              </webResources>  
            </configuration>  
          </plugin>  
    

    `

    0 讨论(0)
  • 2021-01-15 15:40

    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.

    0 讨论(0)
提交回复
热议问题