Maven-web項目

1.需要顯示指定打包爲war

  < packaging>war</packaging>

2. maven 自帶的屬性 

${project.groupId} ${project.version]

3. 使用jetty-maven-plugin對web項目進行測試

    配置jetty 插件:

  

                               <plugin>
					<groupId>org.mortbay.jetty</groupId>
					<artifactId>jetty-maven-plugin</artifactId>
					<version>7.1.0.RC1</version>
					<configuration>
						<scanIntervalSeconds>10</scanIntervalSeconds> //指名掃描間隔時間
						<webAppConfig>
							<contextPath>/account</contextPath> //訪問的路徑
						</webAppConfig>
					</configuration>
				</plugin
修改settings.xml

<pluginGroups>
<pluginGroup>org.moetbat.jetty</pluginGroup>
</pluginGroups>

然後在命令行運行:

mvn jetty:run

mvn jetty:run -Djetty.port=9999


使用Cargo實現自動化部署

cargo-maven2-plugin提供了Maven集成,

步驟:standalone 模式(複製保存) existing模式(指定配置目錄)


  1. <plugin>  
  2.                 <groupId>org.codehaus.cargo</groupId>  
  3.                 <artifactId>cargo-maven2-plugin</artifactId>  
  4.                 <version>1.1.3</version>  
  5.                 <configuration>  
  6.                     <container>  
  7.                         <containerId>tomcat7x</containerId>  
  8.                         <home>E:\tomcat\apache-tomcat-7.0.26</home>  
  9.                     </container>  
  10.                     <configuration>  
  11.                         <type>existing</type>  
  12.                         <home>E:\tomcat\apache-tomcat-7.0.26</home>  
  13.                                 <properties>
  14.                                         <cargo.servlet.port>8090</cargo.servlet.port>
  15.                                  </properties>
  16.                         <!--   
  17.                             <type>standalone</type>  
  18.                             <home>${project.build.directory}/tomcat7x</home>  
  19.                          -->  
  20.                     </configuration>  
  21.                 </configuration>  
  22.             </plugin>  

在settings.xml中配置,可以使用命令 mvn cargo:start 

當使用standalone 時,上述命令不起作用時,使用mvn cargo:run

注意:cargo:start需要額外配置一個<wait>的參數,否則的話雖然cargo:start可以把容器啓動,但是在maven生命週期跑完之後,容器也就立刻關閉了 

這個需要自動啓動tomcat 否則不能訪問。

遠程配置:


  1. <plugin>  
  2.                 <groupId>org.codehaus.cargo</groupId>  
  3.                 <artifactId>cargo-maven2-plugin</artifactId>  
  4.                 <version>1.1.3</version>  
  5.                 <configuration>  
  6.                     <container>  
  7.                         <containerId>tomcat7x</containerId>  
  8.                         <type>remote</type>  
  9.                     </container>  
  10.                     <configuration>  
  11.                         <type>runtime</type>  
  12.                         <properties>  
  13.                             <cargo.remote.username>tomcat</cargo.remote.username>  
  14.                             <cargo.remote.password>tomcat</cargo.remote.password>  
  15.                             <cargo.remote.manager.url>http://localhost:8080/manager</cargo.remote.manager.url>  
  16.                         </properties>  
  17.                     </configuration>  
  18.                 </configuration>  
  19.             </plugin> 

使用命令:mvn cargo:redeploy

注意使用jps查看java進程






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章