1、修改tomcat-user.xml
<role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager"/> <role rolename="admin-gui"/> <user username="admin" password="admin" roles="manager-gui,manager,manager-script,admin-gui"/>2、修改Maven 的setting.xml,在<servers></servers>之间添加:
<server> <id>tomcat</id> <username>admin</username> <password>admin</password> </server>3、在pom.xml中添加:
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <!--这里也可以使用tomcat7-maven-plugin--> <version>2.2</version> <!--最新版本--> <configuration> <url>http://localhost:8080/manager/text</url> <!--配置远程tomcat的路劲--> <username>admin</username> <password>admin</password> <uriEncoding>UTF-8</uriEncoding> <!--tomcat的url编码 达到和修改server.xml文件一样的功能--> </configuration> </plugin>运行:mvn tomcat7:deploy
laolang@laolang-Lenovo-G470:~/git/jcone$ mvn tomcat7:deploy [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building one Maven Webapp 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> tomcat7-maven-plugin:2.2:deploy (default-cli) > package @ one >>> [WARNING] The artifact jstl:jstl:jar:1.1.2 has been relocated to javax.servlet:jstl:jar:1.1.2 [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ one --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ one --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! [INFO] Compiling 22 source files to /home/laolang/git/jcone/target/classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ one --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ one --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! [INFO] Compiling 1 source file to /home/laolang/git/jcone/target/test-classes [WARNING] /home/laolang/git/jcone/src/test/java/com/laolang/daoImpl/EmployeeDaoTest.java: /home/laolang/git/jcone/src/test/java/com/laolang/daoImpl/EmployeeDaoTest.java使用或覆盖了已过时的 API。 [WARNING] /home/laolang/git/jcone/src/test/java/com/laolang/daoImpl/EmployeeDaoTest.java: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ one --- [INFO] Surefire report directory: /home/laolang/git/jcone/target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running com.laolang.daoImpl.EmployeeDaoTest emp:Employee [employeeID=1001, employeeName=老狼, employeeSex=false, employeeBirth=null, employeePhone=15382009723, employeePlace=null, joinTime=null, password=null, isLead=0] e:Employee [employeeID=1001, employeeName=老狼, employeeSex=false, employeeBirth=1991-12-06, employeePhone=15382009723, employeePlace=中国, joinTime=2005-05-18, password=fcl1164891, isLead=0] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.595 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-war-plugin:2.2:war (default-war) @ one --- [INFO] Packaging webapp [INFO] Assembling webapp [one] in [/home/laolang/git/jcone/target/one] [INFO] Processing war project [INFO] Copying webapp resources [/home/laolang/git/jcone/src/main/webapp] [INFO] Webapp assembled in [912 msecs] [INFO] Building war: /home/laolang/git/jcone/target/one.war [INFO] WEB-INF/web.xml already added, skipping [INFO] [INFO] <<< tomcat7-maven-plugin:2.2:deploy (default-cli) < package @ one <<< [INFO] [INFO] --- tomcat7-maven-plugin:2.2:deploy (default-cli) @ one --- [INFO] Deploying war to http://localhost:8080/one Uploading: http://localhost:8080/manager/text/deploy?path=%2Fone Uploaded: http://localhost:8080/manager/text/deploy?path=%2Fone (11910 KB at 14211.4 KB/sec) [INFO] tomcatManager status code:200, ReasonPhrase:OK [INFO] OK - Deployed application at context path /one [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 36.273 s [INFO] Finished at: 2016-02-20T21:38:44+08:00 [INFO] Final Memory: 23M/261M [INFO] ------------------------------------------------------------------------ laolang@laolang-Lenovo-G470:~/git/jcone$