首页 > 其他 > 详细

jenkins maven tomcat做持续集成

时间:2014-05-07 16:58:02      阅读:465      评论:0      收藏:0      [点我收藏+]

maven 采用 maven 3.0以上的版本。tomcat 采用 tomcat 7.0 以上的版本

1. tomcat 配置用户账号和权限

tomcat-users.xml

1
2
3
4
5
<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 

1
2
3
4
5
6
7
8
9
10
11
12
13
<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>

 

在url可以配置本地或者远程的TOMCAT 
path就是在部署上去以后在http://ip:8080/manager/html里面看到部署结果 
server就是一个名字和你maven的settings.xml对应的id一致 
 

2. maven 配置 tomcat 账号

setting.xml 文件

 

1
2
3
4
5
6
7
<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

 

bubuko.com,布布扣
<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>
bubuko.com,布布扣

 

3.2 build 配置节配置部署时测试相关,忽略测试

 

1
2
3
4
5
6
7
8
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.14</version>
    <configuration>
        <skipTests>true</skipTests>
    </configuration>
</plugin>

 

buid下所有插件例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
                <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 错误)

 

jenkins maven tomcat做持续集成,布布扣,bubuko.com

jenkins maven tomcat做持续集成

原文:http://www.cnblogs.com/hujihon/p/3713445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!