Tomcat1—怎么将maven生成的war 文件部署到Tomcat上

这篇文章是看的网上的一个问答,比较基础,先存在我的blog里吧

In this tutorial, we will show you how to use Maven-Tomcat plugin to package and deploy a WAR file to Tomcat, both in Tomcat 6 and 7.

Libraries used :

  1. Maven 3
  2. Tomcat 6.0.37
  3. Tomcat 7.0.53
Tomcat 7
Deploy URL = http://localhost:8080/manager/text
Command = mvn tomcat7:deploy

Tomcat 6
Deploy URL = http://localhost:8080/manager/
Command = mvn tomcat6:deploy

1. Tomcat 7 Example

This example shows you how to package and deploy a WAR file on Tomcat 7.

1.1 Tomcat Authentication
Add an user with roles manager-gui and manager-script.

%TOMCAT7_PATH%/conf/tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>

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

</tomcat-users>

1.2 Maven Authentication
Add above Tomcat’s user in the Maven setting file, later Maven will use this user to login Tomcat server.

%MAVEN_PATH%/conf/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings ...>
	<servers>

		<server>
			<id>TomcatServer</id>
			<username>admin</username>
			<password>password</password>
		</server>

	</servers>
</settings>

1.3 Tomcat7 Maven Plugin
Declares a Maven Tomcat plugin.

pom.xml
<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.2</version>
	<configuration>
		<url>http://localhost:8080/manager/text</url>
		<server>TomcatServer</server>
		<path>/mkyongWebApp</path>
	</configuration>
</plugin>

How it works?
During deployment, it tells Maven to deploy the WAR file to Tomcat server via “http://localhost:8080/manager/text” , on path “/mkyongWebApp“, using “TomcatServer” (in settings.xml) username and password for authentication.

1.4 Deploy to Tomcat
Commands to manipulate WAR file on Tomcat.

mvn tomcat7:deploy
mvn tomcat7:undeploy
mvn tomcat7:redeploy

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值