热部署指在eclipse就可以运行调试maven项目。
1. 编辑 tomcat 文件:tomcat-users.xml 添加如下内容:
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,admin-gui"/>
2. 在 maven 安装目录conf/settings.xml 文件中加入一个server:
<server>
<id>tomcat7</id>
<username>admin</username>
<password>admin</password>
</server>
3. 在项目pom.xml文件中加入插件:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
<url>http://localhost:8080/manager/text</url>
<server>tomcat7</server>
</configuration>
</plugin>
4. 然后 maven 编译项目之后,使用 mvn tomcat7:redeploy 即可部署启动项目,当然 tomcat 要提前启动。
问题:
1. 第二次部署时提示出错:
[INFO] FAIL - Unable to delete [D:\j2ee\apache-tomcat-7.0.52\webapps\ROOT]. The continued presence of this file may cause problems.
[INFO] FAIL - Application already exists at path /
也就是ROOT目录删除不了,不让部署。
网上google之后,发现解决办法:
http://stackoverflow.com/questions/14873219/cannot-undeploy-a-web-app-completely-in-tomcat-7
修改 D:\j2ee\apache-tomcat-7.0.52\conf\context.xml文件
修改开头的<Context> 为 <Context antiResourceLocking="true" > 即可。
2. 第二次部署时出错:
[INFO] FAIL - Context / is defined in server.xml and may not be undeployed
[INFO] FAIL - Application already exists at path /
解决办法:
解决方法是在pom.xml文件中配置tomcat7-maven-plugin插件时加入参数update
<update>true</update>