tomcat热部署

软件版本:maven 3.0.3+tomcat 6.0+myeclipse6.5

事先在myeclipse6.5 中建立一个web项目demo

1、管理自己的tomcat
到tomcat的安装目录中,G:\tomcat6.0\conf\tomcat-users.xml在其中增加一个用户定义,默认是没有用户的,结果如下:
<tomcat-users>

<user username="admin" password="password" roles="manager"/>

</tomcat-users>
增加了一个admin用户,密码是password,角色是管理员。

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

<servers>

<!-- 增加一个测试服务器 -->

<server>

<id>tomcat</id>

<username>admin</username>

<password>password</password>

</server>

</servers>

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

<build>

<plugins>

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>tomcat-maven-plugin</artifactId>

<version>1.0-beta-1</version>

<configuration>

<url>http://localhost:8080/manager/html</url>

<server>tomcat</server>

</configuration>

</plugin>

</plugins>

</build>


4、打开tomcat

如果事先没有打开tomcat,会报错:
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:redeploy (default-cli) on project demo7: Cannot invoke Tomcat manager: Connection refused: connect -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


5、右键demoRun As 选择 Maven build,在Goals中输入package tomcat:redeploy


6、点击Run按钮,注意看Console,看看有没有错误,没有错误的话,访问: http://localhost:8080/demo

出现Hello World!就OK了

猜你喜欢

转载自meifage.iteye.com/blog/1090878