Maven +Tomcat+m2eclipse的热部署(hot deploy)

软件版本:maven 2.2 tomcat 6.0,Eclipse 3.4

首先是建立环境,tomcat、maven、m2eclipse都不说了,这不配好,剩下的你也别看了。都准备好了,那我们就一步一步的开始了。

  1. 管理自己的tomcat.

到tomcat的安装目录中,F:\J2EE\apache-tomcat-6.0.24\conf在其中增加一个用户定义,默认是没有用户的,结果如下:

 

?
1
2
3
4
5
< tomcat-users >
 
< user username = "admin" password = "password" roles = "manager" />
 
</ tomcat-users >

 

增加了一个admin用户,密码是password,角色是管理员。

2、 启动tomcat,然后访问 http://localhost:8080/manager/html,输入admin/password,如果出现以下界面,表示tomcat一切OK:

clip_image002

3、 在maven的setting.xml中定义本机的tomcat,增加如下内容:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
< servers >
 
<!-- 增加一个测试服务器 -->
 
< server >
 
< id >tomcat</ id >
 
< username >admin</ username >
 
< password >password</ password >
 
</ server >
 
</ servers >

记住这里的id,等会要用到。

4、 在Eclipse中建立一个打包类型为war的maven项目:

clip_image004

如果这步都不会,那就先修行maven再说。

5、 修改pom.xml文件,格式如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
< modelVersion >4.0.0</ modelVersion >
 
< groupId >com.world</ groupId >
 
< artifactId >demo</ artifactId >
 
< version >0.0.1-SNAPSHOT</ version >
 
< packaging >war</ packaging >
 
< build >
 
< plugins >
 
< plugin >
 
< groupId >org.codehaus.mojo</ groupId >
 
< artifactId >tomcat-maven-plugin</ artifactId >
 
< version >1.0-beta-1</ version >
 
< configuration >
 
 
< server >tomcat</ server >
 
</ configuration >
 
</ plugin >
 
</ plugins >
 
</ build >
 
</ project >

看清楚configuration配置,别的没啥,<url>标签指明tomcat的管理器地址,<server>标签指明使用的是那个服务器。

6、 在项目中增加web.xml和一个测试文件HotDeplyTest.jsp。

HotDeplyTest.jsp内容如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<%@ page language="java" contentType="text/html; charset=GB18030"
 
pageEncoding="GB18030"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
< html >
 
< head >
 
< meta http-equiv = "Content-Type" content = "text/html; charset=GB18030" >
 
< title >Insert title here</ title >
 
</ head >
 
< body >
 
< font size = 6 color = red >< BR ></ BR > If you see this, It turns out your Hot Deploy ENV is OK!</ font >
 
</ body >
 
</ html >

Web.xml啥内容都没有,随便从别的项目中拷贝一个过来就成。

7、 Demo项目,鼠标右键,Run As 选择 Maven build,出现如下界面:

clip_image006

在Goals中添加点东西:package tomcat:redeploy

clip_image008

这句话是什么意思呢?运行build的目的就是打包,同时部署到tomcat上。

8、 点击Run按钮,注意看Console,看看有没有错误,没有错误的话,访问: http://localhost:8080/demo/HotDeployTest.jsp,如果出现如下界面,则表示一切万事大吉:

clip_image010

然后你就可以开始继续蹂躏了,加入自己的精华吧!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值