添加maven插件,使war自动部署到Tomcat的webapps目中。
1.修改Tomacat配置 修改tomcat安装目录下的server.xml和tomcat-users.xml,在tomcat-users.xml中添加用户和权限
1 2 3 4 5 6 7 8 9 10 11 <tomcat-users xmlns ="http://tomcat.apache.org/xml" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="http://tomcat.apache.org/xml tomcat-users.xsd" version ="1.0" > <role rolename ="manager" /> <role rolename ="manager-gui" /> <role rolename ="admin" /> <role rolename ="admin-gui" /> <role rolename ="manager-script" /> <user username ="tomcat" password ="1q2w3e4r" roles ="admin-gui,admin,manager-gui,manager,manager-script" /> </tomcat-users >
在server.xml中配置上面添加的tomcat用户
1 2 3 4 5 6 7 <Server > <server > <id > TomcatServer</id > <username > tomcat</username > <password > 1q2w3e4r</password > </server > </Server >
2.在mvn项目的pom.xml配置中添加tomcat7插件 配置插件中url为本机的tomcat服务地址,也可以是远程地址。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 <build > <plugins > <plugin > <groupId > org.apache.tomcat.maven</groupId > <artifactId > tomcat7-maven-plugin</artifactId > <version > 2.0</version > <configuration > <url > http://127.0.0.1:8088/manager/text</url > <server > TomcatServer</server > <username > tomcat</username > <password > 1q2w3e4r</password > <path > /${project.build.finalName}</path > </configuration > </plugin > </plugins > </build >
3.执行tomcat7:deploy 在idea中执行tomcat7:deploy命令,或者是命令行输入:mvn tomcat7:deploy
4.部署成功
5.出现错误 (1) 在执行命令是出现测试错误: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project demo: There are test failures.
先跳过测试好了,pom.xml中添加
1 2 3 4 5 6 7 8 9 10 11 <build > <plugins > <plugin > <groupId > org.apache.maven.plugins</groupId > <artifactId > maven-surefire-plugin</artifactId > <configuration > <testFailureIgnore > true</testFailureIgnore > </configuration > </plugin > </plugins > </build >
(2) 在项目目录下,出现了莫名奇妙的replay_pid212.log和hs_err_pid212.log
查看文件内容,多半是内存不足。
(3) 出现了:Cannot invoke Tomcat manager: Connection reset by peer: socket write error
好像是上传到一半然后文件就断掉了。
尝试着把已经上传的war删除试试,结果成功了。