maven项目部署到tomcat

方法一:部署到项目target目录,即对每个项目都新建一个tomcat实例

只需在pom文件中加入

<build>
	<plugins>
		<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>tomcat-maven-plugin</artifactId>
			<version>1.1</version>
			<configuration>
				<url>http://localhost:8080/manager/html</url>
				<server>tomcat-6.0.29</server>
			</configuration>
		</plugin>
	</plugins>
</build>

注意,其中server的值tomcat-6.0.29为内置的tomcat版本

右键项目 run as--> maven build ..

goals输入goals:tomcat:run

即能在项目的target目录看到一个tomcat实例

注意:tomcat官网的maven plugin已经分离,tomcat6-maven-plugin、tomcat7-maven-plugin,并且groupid也不一样了,我用tomcat6-maven-plugin出现不能多次run的问题,略

方法二:部署到指定的tomcat目录

1:在tomcat的目录conf/tomcat-users.xml中加入user

<role rolename="manager-gui"/>
<role rolename="manager-script"/> 
<user username="tomcat" password="password" roles="manager-gui,manager-script"/>

2:maven的用户目录下修改settings.xml,加入server

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

3:pom.xml中加入

<build>
	<plugins>
		<plugin>
			<groupId>org.codehaus.mojo</groupId>
			<artifactId>tomcat-maven-plugin</artifactId>
			<version>1.1</version>
			<configuration>
				<url>http://localhost:8080/manager/html</url>
				<server>tomcat</server>
			</configuration>
		</plugin>
	</plugins>
</build>

右键项目,输入命令 tomat:redeploy即可将项目部署到本地tomcat中,不过执行命令之前须将tomcat启动

方法三:cargo插件部署至tomcat,2012年10月28日0:52:11,

cargo部分分两种方式,一种是standalone,一种是existing,显然就是新建一个tomcat实例和直接部署到本地tomcat实例,当然,也可以部署到远程tomcat,不过需要提供认证

这里给出existing部署,其余的可以参考官方文档

<plugin>
	<groupId>org.codehaus.cargo</groupId>
	<artifactId>cargo-maven2-plugin</artifactId>
	<version>1.3.0</version>
	<configuration>
		<container>
			<containerId>tomcat6x</containerId>
			<home>D:\tomcat-6.0.36</home>
		</container>
	        <configuration>
	               <type>existing</type>
	               <home>D:\tomcat-6.0.36</home>
	         </configuration>
	</configuration>
</plugin>

官方文档:http://cargo.codehaus.org/Tomcat+6.x

-------------------------------------------------

jetty-maven-plugin自动识别修改然后重新部署,

官方文档:http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin

<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>7.6.7.v20120910</version>
				<configuration>
					<scanIntervalSeconds>10</scanIntervalSeconds>
					<systemProperties>
						<systemProperty>
							<name>jetty.port</name>
							<value>8881</value>
						</systemProperty>
						<systemProperty>
							<name>org.eclipse.jetty.util.URI.charset</name>
         					<value>UTF-8</value>
						</systemProperty>
					</systemProperties>
					<webAppConfig>
						<contextPath>/kjpta8</contextPath>
					</webAppConfig>
				</configuration>
			</plugin>
 

猜你喜欢

转载自utopialxw.iteye.com/blog/1706736