Alternate port for Tomcat (not 8080) when starting with Maven?

Viewed 89741

Is there an easy way to specify an alternate port for Tomcat in the pom or on the commandline. I'd like to have several projects running on the same machine.

11 Answers

If you are using the maven tomcat plugin, you can specify a context.xml by adding a plugin configuration block to the pom.xml:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>tomcat-maven-plugin</artifactId>
        <version>1.0-beta-1</version>
        <configuration>
          <mode>both</mode>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

The default context.xml file used is located at src/main/webapp/META-INF/context.xml.

Set different ports there.

I know it's a very old question which not have answer yet.

And I've got the similar question when I need to convert a old project which use outer tomcat to embedded tomcat use tomcat7-maven-plugin.

And what I need is build an executable jar. But existing answer cannot work for me... whatever i run java -jar project-name.jar after mvn package. it's always running on port 8080 which is not i wanted... Then I search the doc Executable War and what i fixed is just add a param in command

java -jar my_project.jar -httpPort 9091

which in doc:

usage: java -jar [path to your exec war jar] ...

-httpPort http port to use

-httpsPort https port to use ...

hope it useful.

Related