1. 程式人生 > >【Java】Maven Tomcat外掛使用

【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/