在web项目的pom.xml中添加如下:
<build> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <port>8080</port> <path>/web</path> <uriEncoding>UTF-8</uriEncoding> <finalName>web</finalName> <server>tomcat7</server> </configuration> </plugin> </plugins> </build>
然后项目右键--run as -- maven build -- 输入参数 tomcat7:run。需要的构件下载完成后即可通过http://localhost:8080/web访问项目
该插件可以远程部署web项目,常用命令有:
命令 | 描述 |
tomcat7:deploy | 部署一个web war包 |
tomcat7:reload | 重新加载web war包 |
tomcat7:start |
启动tomcat |
tomcat7:stop |
停止tomcat |
tomcat7:undeploy |
停止一个war包 |
tomcat7:run | 启动嵌入式tomcat ,并运行当前项目 |