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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM