Maven部署项目到Tomcat 7

1. Tomcat Authentication

%CATALINA_HOME%/conf/tomcat-users.xml

 

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

 为了成功执行maven 部署 我们需要开启tomcat支持 admin-script,manager-gui的权限。

 

admin-script:是让tomcat支持以脚本的形式来管理

 

manager-gui:是让tomcat支持图形化的管理界面。

 

 

2. Maven Authentication

%M2_HOME%/conf/settings.xml

 

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

 

 

3.tomcat7-maven-plugin

 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.fool</groupId>
	<artifactId>mvc</artifactId>
	<name>mvc</name>
	<packaging>war</packaging>
	<version>1</version>

	<properties>
		<project.build.finalName>mvc</project.build.finalName>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<spring-version>3.1.2.RELEASE</spring-version>
		<hibernate-version>3.6.10.Final</hibernate-version>
		<struts-version>2.3.4.1</struts-version>
		<commons-dbcp-version>1.4</commons-dbcp-version>
		<cglib-version>2.2.2</cglib-version>
		<jstl-version>1.2</jstl-version>
		<servlet-version>3.0-alpha-1</servlet-version>
		<jsp-version>2.2.1-b03</jsp-version>
		<slf4j-nop-version>1.6.6</slf4j-nop-version>
		<junit-version>4.10</junit-version>
		<mysql-connector-version>5.1.21</mysql-connector-version>
	</properties>

	<dependencies>
		<!-- Spring -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring-version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>${spring-version}</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-nop</artifactId>
			<version>${slf4j-nop-version}</version>
		</dependency>

		<!-- Servlet -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>${jstl-version}</version>
		</dependency>

		<!-- Test -->
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>${junit-version}</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<artifactId>maven-eclipse-plugin</artifactId>
				<version>2.9</version>
				<configuration>
					<additionalProjectnatures>
						<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
					</additionalProjectnatures>
					<additionalBuildcommands>
						<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
					</additionalBuildcommands>
					<downloadSources>true</downloadSources>
					<downloadJavadocs>true</downloadJavadocs>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>2.5.1</version>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.0-beta-1</version>
				<configuration>
					<url>http://127.0.0.1:8080/manager/html</url>
					<server>Tomcat7</server>
					<path>/${project.build.finalName}</path>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>


4. Deploy to Tomcat
mvn tomcat7:deploy
  还有一个更简单的方法
mvn tomcat:run
 


 

 

 


 






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值