在本教程中,我们将学习如何使用Maven的Tomcat插件打包并部署一个WAR文件到Tomcat(Tomcat的6和7。
要用到工具:
- Maven 3
- Tomcat 6.0.37
- Tomcat 7.0.53
Tomcat 7
发布URL = http://localhost:8080/manager/text 命令 = mvn tomcat7:deployTomcat 6
发布 URL = http://localhost:8080/manager/ 命令 = mvn tomcat6:deploy1. Tomcat 7 示例
这个例子说明了如何在Tomcat7打包并部署WAR文件。
1.1 Tomcat 认证
添加具有角色管理器GUI和管理脚本的用户。%TOMCAT7_PATH%/conf/tomcat-users.xml
1.2 Maven 认证
添加在上面Maven 设置文件的 Tomcat 用户,是之后Maven使用此用户来登录Tomcat服务器。%MAVEN_PATH%/conf/settings.xml
TomcatServer admin password
1.3 Tomcat7 Maven 插件
声明一个Maven的Tomcat插件。pom.xml
org.apache.tomcat.maven tomcat7-maven-plugin 2.2 http://localhost:8080/manager/text TomcatServer /yiibaiWebApp
怎么运行的?
在部署过程中,它告诉 Maven 通过部署 WAR 文件Tomcat服务器, “http://localhost:8080/manager/text” , 在路径“/yiibaiWebApp“上, 使用 “TomcatServer” (settings.xml) 用户名和密码来进行认证。1.4 发布到Tomcat
以下的命令是用来操纵Tomcat WAR文件。mvn tomcat7:deploy mvn tomcat7:undeploy mvn tomcat7:redeploy
示例
> mvn tomcat7:deploy...[INFO] Deploying war to http://localhost:8080/yiibaiWebAppUploading: http://localhost:8080/manager/text/deploy?path=%2FyiibaiWebApp&update=trueUploaded: http://localhost:8080/manager/text/deploy?path=%2FyiibaiWebApp&update=true (13925 KB at 35250.9 KB/sec)[INFO] tomcatManager status code:200, ReasonPhrase:OK[INFO] OK - Deployed application at context path /yiibaiWebApp[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 8.507 s[INFO] Finished at: 2015-08-05T11:35:25+08:00[INFO] Final Memory: 28M/308M[INFO] ------------------------------------------------------------------------
2. Tomcat 6 示例
这个例子说明了如何在Tomcat6打包和部署WAR文件。这些步骤和Tomcat7是一样的,只是部署URL和命令名称不同。
2.1 Tomcat 认证
%TOMCAT6_PATH%/conf/tomcat-users.xml
2.2 Maven 认证
%MAVEN_PATH%/conf/settings.xml
TomcatServer admin password
2.3 Tomcat6 Maven 插件
pom.xml
org.apache.tomcat.maven tomcat6-maven-plugin 2.2 http://localhost:8080/manager TomcatServer /yiibaiWebApp
2.4 发布到Tomcat
mvn tomcat6:deploy mvn tomcat6:undeploy mvn tomcat6:redeploy
示例
> mvn tomcat6:deploy...[INFO] Deploying war to http://localhost:8080/yiibaiWebAppUploading: http://localhost:8080/manager/deploy?path=%2FyiibaiWebAppUploaded: http://localhost:8080/manager/deploy?path=%2FyiibaiWebApp (13925 KB at 32995.5 KB/sec)[INFO] ------------------------------------------------------------------------[INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------[INFO] Total time: 22.652 s[INFO] Finished at: 2014-08-05T12:18:54+08:00[INFO] Final Memory: 30M/308M[INFO] ------------------------------------------------------------------------