maven 采用 maven 3.0以上的版本。tomcat 采用 tomcat 7.0 以上的版本
1. tomcat 配置用户账号和权限
tomcat-users.xml
<role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx,manager-status"/>
创建其他的role貌似不行,因为你访问http://ip:8080/manager/html然后弹出输入框需要用户名和密码,随意输入一个就会有403访问权限受限制的页面,在这个页面里面定义这个四个role.
修改完成以后记得重启tomcat
项目的设置,在pom.xml需要引入针对tomcat7的plugin
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <url>http://192.168.0.51:8081/manager/text</url> <update>true</update> <server>servername</server> <username>admin</username> <password>admin</password> <path>/info</path> </configuration> </plugin>
path就是在部署上去以后在http://ip:8080/manager/html里面看到部署结果
server就是一个名字和你maven的settings.xml对应的id一致
2. maven 配置 tomcat 账号
setting.xml 文件
<servers> <server> <id>servername</id> <username>admin</username> <password>admin</password> </server> </servers>
3. 项目 pom.xml 配置
3.1 build 配置节配置 tomcat 发布插件,注意 server 必须与2中一致,增加update 配置项,更新发布的文件,
tomcat 的发布路径为 http://serverip:port/manager/text
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <url>http://192.168.0.51:8081/manager/text</url> <update>true</update> <server>servername</server> <username>admin</username> <password>admin</password> <path>/info</path> </configuration> </plugin>
3.2 build 配置节配置部署时测试相关,忽略测试
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.14</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin>
buid下所有插件例子
<plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <executions> <execution> <phase>compile</phase> </execution> </executions> </plugin> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.4</version> <executions> <execution> <phase>compile</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>2.4.1</version> <configuration> <filesets> <fileset> <directory>src/main/webapp/WEB-INF/lib</directory> <followSymlinks>false</followSymlinks> </fileset> </filesets> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.14</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <!--<groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <version>1.1</version> --> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <url>http://192.168.0.51:8081/manager/text</url> <update>true</update> <server>booksair</server> <username>admin</username> <password>admin</password> <path>/info</path> </configuration> </plugin> </plugins>
4. jenkins 项目配置
jenkins mavne goal目标为(针对tomcat 7)clean install tomcat7:deploy
tomcat 配置
WAR/EAR files:**/site.war
tomcat url: http://serverip:port/
(这里不用配置项目路径 或者 manager 路径,否则会出现 Unkown /manager/text/list 错误)