Maven war context string app

I create a military application file using the maven configuration below, however, when I run the application in tomcat, the Context Root root is set to "/CommerceApi-0.0.1-SNAPSHOT/"

I want this to be set to "/ api",

any ideas ?, below - pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>CommerceApi</groupId>
  <artifactId>CommerceApi</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
   <dependencies>
    <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.13</version>
    </dependency>
    <dependency>
      <groupId>CommerceApiCommon</groupId>
      <artifactId>CommerceApiCommon</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>
+4
source share
3 answers

There are three ways to do this:

1. If you do not use Eclipse / MyEclipse to deploy the application to the application server -

You need to use the maven-war plugin, you can specify warName in the configuration section.

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <warName>customwarname</warName>
    </configuration>
</plugin>

2. Eclipse/MyEclipse -

eclipse eclipse, maven.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.10</version>
    <configuration>
        <wtpversion>2.0</wtpversion>
        <wtpContextName>customwarname</wtpContextName>
    </configuration>
</plugin>

eclipse.

   mvn eclipse:eclipse -Dwtpversion=2.0

Eclipse, , Properties- > Web, , .

, m2eclipse, .

3. : , , URL- .

+4

. , Tomcat . Tomcat . . Jenkins CI, .

, Tomcat.

+1

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


All Articles