`
zhoucl
  • 浏览: 48911 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Maven Web项目通过cargo-maven2-plugin部署至Tomcat

 
阅读更多

Maven接触有一阵了,也换上了开源的Eclipse进行熟悉,在使用的过程中也换这个试一下那个尝下鲜,首先使用的是tomcat-maven-plugin,通过这个插件将Web项目部署至Tomcat容器当中以下是具体的配置:

1、在~/.m2/settings.xml中增加如下的Tomcat服务器配置

<server>
	<id>TestMaven</id>
	<username>tomcat</username>
	<password>tomcat</password>
</server>

2、在相应的pom.xml中做如下的配置:

<build>
	... ...
	<plugins>
	  ... ...
	  <plugin>
		<groupId>org.codehaus.mojo</groupId>
		<artifactId>tomcat-maven-plugin</artifactId>
		<configuration>
			<url>http://localhost:8080/manager</url>
			<server>TestMaven</server>
			<path>/test</path>
		</configuration>
	</plugin>
	</plugins>
</build>

3、运行mvn install即可将项目部署至webapps/test目录下了,具体的可参考网址:http://mojo.codehaus.org/tomcat-maven-plugin/

 

但是,在使用的过程中,这种方式貌似不能满足需求,因此后面使用的是cargo-maven2-plugin插件,较为灵活的一个Deploy插件,具体配置如比上面的 tomcat-maven-plugin稍微有点儿复杂,部分还有不清楚,先写上以后再慢慢研究,配置如下:

<build>       
        <plugins>
  		<plugin>
			<!-- 指定插件名称及版本号 -->
  			<groupId>org.codehaus.cargo</groupId>
  			<artifactId>cargo-maven2-plugin</artifactId>
  			<version>1.0.3</version>
  			
			<!-- 插件的Tomcat6.x配置 -->
  			<configuration>
  				<wait>true</wait>		<!--是否说明,操作start、stop等后续操作必须等前面操作完成才能继续-->
  				<container>				<!-- 容器的配置 -->
  					<containerId>tomcat6x</containerId>						<!-- 指定tomcat版本  -->
  					<type>installed</type>									<!-- 指定类型:standalone, installed等 -->
  					<home>E:\webServers\apache-tomcat-6.0.32-test</home>	<!-- 指定Tomcat的位置,即catalina.home -->
  				</container>
  				
  				<configuration>			<!-- 具体的配置 -->
  					<type>existing</type>									<!-- 类型,existing:存在 -->
  					<home>E:\webServers\apache-tomcat-6.0.32-test</home>	<!-- Tomcat的位置,即catalina.home -->
  					<properties>											<!-- 配置属性 -->
  						<cargo.tomcat.manager.url>http://localhost:8080/manager</cargo.tomcat.manager.url>		<!-- 管理地址 -->
  						<cargo.remote.username>tomcat</cargo.remote.username>									<!-- Tomcat用户名 -->
  						<cargo.remote.password>tomcat</cargo.remote.password>									<!-- Tomcat密码 -->
  						<cargo.tomcat.ajp.port>8009</cargo.tomcat.ajp.port>										<!-- Ajp端口 -->
  					</properties>
  				</configuration>
  				
  				<deployer>											<!-- 部署配置 -->
  					<type>installed</type>							<!-- 类型 -->
  					<deployables>									<!-- 部署设置 -->
  						<deployable>								<!-- 部署的War包名等 -->				
  							<groupId>org.test</groupId>
  							<artifactId>testwebapp</artifactId>
  							<type>war</type>
  							<properties>
  								<context>testwebapp</context>	<!-- 部署路径 -->
  							</properties>
  						</deployable>
  					</deployables>
  				</deployer>
  			</configuration>
  			
  			<executions>
				<!-- 执行的动作 -->
  				<execution>
  					<id>verify-deployer</id>
  					<phase>install</phase>		<!-- 解析install -->
  					<goals>
  						<goal>deployer-deploy</goal>
  					</goals>
  				</execution>
  				
  				<execution>
  					<id>clean-deployer</id>
  					<phase>clean</phase>
  					<goals>
  						<goal>deployer-undeploy</goal>
  					</goals>
  				</execution>
  			</executions>
  		</plugin>
  	</plugins>
</build>

不详细的解释在XML当中,直接运行mvn install OK!~~

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics