wanmin444 发表于 2017-2-6 08:06:35

maven工程在tomcat服务器上的自动化部署

  1. 首先你的
web
工程必须是一个
maven
工程。

  2.修改
tomcat

tomcat-users.xml
文件,目录为
conf\tomcat-users.xml
,加入以下内容:


<role rolename="manager"/>
<user username="tomcat" password="123456" roles="manager"/>

  3. 在
maven
工程的
pom
文件中加入
tomcat-maven-plugin
插件,以下为
pom
代码示例:


<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.malangmedia</groupId>
<artifactId>malangmedia.autoDeployToTomcat</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>autoDeployToTomcat</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<finalName>autoTomcat</finalName>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- 设置war包名称 -->
<finalName>${finalName}</finalName>
<plugins>
<!-- tomcat自动部署插件 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<url>http://localhost:8080/manager</url>   
<username>tomcat</username>   
<password>123456</password>   
<path>/${finalName}</path>
</configuration>
</plugin>
</plugins>
</build>
</project>

  4.将该工程导入
SVN


  5. 在
hudson
中为该
SVN
地址新建一个工程,在配置
maven
运行命令时,在
install
命令后,加入一个
tomcat
部署

      的命令。

      Install
在前,
tomcat:redeploy
在后,顺序不能错,这样才能保证
install
成功后再部署。

  6. 如此,每当
SVN
版本更新后,
hudson
就会自动编译该工程,编译成功后,再通过
tomcat-maven-plugin
插件自动部署至指定
tomcat
服务器,且该部署为热部署,服务器不需要重启,并支持远程部署。
页: [1]
查看完整版本: maven工程在tomcat服务器上的自动化部署