开发环境 sts,在将maven打成的war包自动部署到tomcat 操作:
1、配置tomcat-users.xml文件
在tomcat安装目录下找到tomcat-users.xml文件。该文件路径为【tomcat安装根目录】/conf/
修改文件内容,增加下列内容:
<tomcat-users> <role rolename="manager"/> <role rolename="admin"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username = "manager" password = "tomcat" roles = "admin,manager,manager-gui,manager-script" /> </tomcat-users>
启动tomcat7,然后访问 http://localhost:8080/manager/html,输入manager/tomcat,如果出现以下界面,表示tomcat一切OK
如果是Tomcat6 http://localhost:8080/manager
2、配置maven 的setting.xml 文件
在Maven的conf目录中的setting.xml servers节点增加
<server> <id>tomcat7</id> <username>manager</username> <password>tomcat</password> </server>
3、配置项目pom.xml文件
<plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <!-- 告诉maven用manager/tomcat账号访问setting.xml中id为tomcat7的服务器,去http://localhost:8081/manager/text这个地址发布我的项目 --> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat7</server> <username>manager</username> <password>tomcat</password> <ignorePackaging>true</ignorePackaging> </configuration> </plugin>
注:此处的url 注意是xxx/manager/text 并非是 xxx/manager/html 原因是我用的tomcat 是tomcat7 的版本,我在这里由于将url写错,调试了一下午,希望看到我博客的同学能够参考下这里
4:最后一步:运行tomcat7:redeploy 此时在tomcat webapps底下可以查看到xxx.war包信息了。
5:如果你的war包大于50M(tomcat7默认最大支持war包50M,超过50M会报错),需要修改
webapps\manager\WEB-INF\web.xml配置文件:原配置文件信息如下:
<multipart-config> <!-- 50MB max --> <max-file-size>52428800</max-file-size> <max-request-size>52428800</max-request-size> <file-size-threshold>0</file-size-threshold> </multipart-config>
此时需要将52428800改的大一些,就可以支持大于50M的war包了。