【Java】Maven Tomcat插件使用

  本例是用的是tomcat7-maven-plugin 插件

依赖

  tomcat7-maven-plugin 插件的pom.xml依赖为

1 <dependency>
2     <groupId>org.apache.tomcat.maven</groupId>
3     <artifactId>tomcat7-maven-plugin</artifactId>
4     <version>2.1</version>
5 </dependency>

使用

  1、新建一个maven web项目

  2、在pom文件中添加插件

 1   <build>
 2     <plugins>
 3       <plugin>
 4         <groupId>org.apache.tomcat.maven</groupId>
 5         <artifactId>tomcat7-maven-plugin</artifactId>
 6         <version>2.1</version>
 7         <executions>
 8           <execution>
 9             <id>tomcat-run</id>
10             <goals>
11               <goal>exec-war-only</goal>
12             </goals>
13             <phase>package</phase>
14             <configuration>
15               <!-- ServletContext path -->
16               <path>/webapp</path>
17             </configuration>
18           </execution>
19         </executions>
20       </plugin>
21     </plugins>
22   </build>

  3、打包maven web项目,可以在target目录中,找到jar包
           

  4、使用java命令运行jar包,命令:java -jar xxx-war-exec.jar
    

  5、浏览器访问地址:http://localhost:8080/webapp/
    

猜你喜欢

转载自www.cnblogs.com/h--d/p/9904920.html