Maven provides support for running web applications in embedded tomcat server.
Use the following steps to configure local tomcat server and run it using maven command:
- Add maven dependency for tomcat embedded plugin to web project
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> ... <dependencies> ... </dependencies> <build> <finalName>sampleproject-web</finalName> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin> </plugins> </build> </project>
2. Use following maven command to run the application in embedded tomcat server
mvn tomcat7:run
tomcat7:run -Dstarttomcat -Dtomcat.httpPort=9080