介绍:本实验环境是在本地笔记本电脑上进行(windows7-x64)

1、首先在本地安装VisulSVN+TortoiseSVN

2、下载并安装jenkins,下载地址是 http://mirrors.jenkins-ci.org/war/

3、被本地配置Maven,并与eclipse集成(可以在网上搜,这一步很简单)

4、在本地eclipse开发环境中,创建Maven工程,工程的名字是HelloWorld

其中,pom.xml文件中的内容是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cn.xxs</groupId>
  <artifactId>HelloWorld</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>HelloWorld Maven Webapp</name>
  <url>http://maven.apache.org</url>
 <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-core</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-web</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-oxm</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-tx</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-jdbc</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-aop</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context-support</artifactId>
		<version>${spring.version}</version>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-aop</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-test</artifactId>
		<version>${spring.version}</version>
	</dependency>

	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis</artifactId>
		<version>${mybatis.version}</version>
	</dependency>

	<dependency>
		<groupId>org.mybatis</groupId>
		<artifactId>mybatis-spring</artifactId>
		<version>1.2.2</version>
	</dependency>

	<dependency>
		<groupId>com.alibaba</groupId>
		<artifactId>druid</artifactId>
		<version>1.0.9</version>
	</dependency>

	<dependency>
		<groupId>org.codehaus.jackson</groupId>
		<artifactId>jackson-mapper-asl</artifactId>
		<version>1.9.13</version>
	</dependency>

	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>jstl</artifactId>
		<version>1.2</version>
	</dependency>
	<dependency>
		<groupId>taglibs</groupId>
		<artifactId>standard</artifactId>
		<version>1.1.2</version>
	</dependency>
	<dependency>
		<groupId>commons-fileupload</groupId>
		<artifactId>commons-fileupload</artifactId>
		<version>${commonupload.version}</version>
	</dependency>
	<dependency>
		<groupId>org.apache.ant</groupId>
		<artifactId>ant</artifactId>
		<version>1.9.4</version>
	</dependency>

	<dependency>
		<groupId>log4j</groupId>
		<artifactId>log4j</artifactId>
		<version>${log4j.version}</version>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-api</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-log4j12</artifactId>
		<version>${slf4j.version}</version>
	</dependency>
	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc14</artifactId>
		<version>10.2.0.4.0</version>
	</dependency>
	<dependency>
		<groupId>mysql</groupId>
		<artifactId>mysql-connector-java</artifactId>
		<version>5.1.29</version>
	</dependency>
	<dependency>
		<groupId>org.apache.poi</groupId>
		<artifactId>poi</artifactId>
		<version>${poi.version}</version>
	</dependency>    
  </dependencies>
  
  <build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>2.5</version>
			<configuration>
				<source>1.6</source>
				<target>1.6</target>
				<encoding>UTF-8</encoding>
			</configuration>
		</plugin>
		<plugin>  
               <groupId>org.apache.maven.plugins</groupId>  
               <artifactId>maven-resources-plugin</artifactId>  
               <version>2.6</version>  
               <configuration>  
                   <encoding>UTF-8</encoding> 
               </configuration>  
           </plugin>
            <plugin>
               <groupId>org.apache.tomcat.maven</groupId>
               <artifactId>tomcat7-maven-plugin</artifactId>
               <version>2.2</version>
               <configuration>
                   <port>9090</port>
                   <uriEncoding>UTF-8</uriEncoding>
                   <server>tomcat7</server>
               </configuration>
        </plugin>   
         
	</plugins>
    <finalName>HelloWorld</finalName>
  </build>
  
  <properties>
  	<spring.version>4.0.6.RELEASE</spring.version>
	<mybatis.version>3.2.4</mybatis.version>
	<!-- log4j日志文件管理包版本 -->
	<slf4j.version>1.7.7</slf4j.version>
	<log4j.version>1.2.17</log4j.version>
	<poi.version>3.10-FINAL</poi.version>
	<commonupload.version>1.3.1</commonupload.version>
	
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
	<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
		
	<maven.compiler.encoding>UTF-8</maven.compiler.encoding>  
  </properties>
</project>
5、jenkins系统配置

在开始配置之前,先启动jenkins,我将jenkins的根目录设置在D:\bmsprom\jenkins,然后编写下面的bat的文件来方便启动

set JENKINS_HOME=D:\bmsprom\jenkins

cd /d %JENKINS_HOME%

java -jar %JENKINS_HOME%\jenkins.war --httpPort=8081

1)添加JDK


2)添加Maven


3)添加一个名称为HelloWorld的任务


4)配置SubVersion


5)构建触发条件


6)配置打包


7)打包工程后将war提交到指定的tomcat


注意1:tomcat的用户名和密码是在tomcat的conf的目录下的添加如下内容:

<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx"/>

注意2:

 WAR/EAR files 这个里面配置的是:相对于jenkins的workspace目录的相对路径.  我的全路径是D:\bmsprom\jenkins\workspace\HelloWorld\target,其中D:\bmsprom\jenkins是jenkins的根目录

    context path  /   #/ 代表的是会把crm.adminWeb.war 换成ROOT.war放到 tomcat的webapps目录.

    tomcat的信息主要是用户名和密码(来自tomcat-users.xml)  还有tomcat访问的地址http://localhost:8080

8)立即构建

9)测试

a.在eclipse中直接对工程代码进行修改(将index.jsp页面中的内容改成update of the first time!!)

b.通过eclipse集成的svn插件向svn更新提交代码



c.观察jenkins的日志变化


d.查看tomcat的后台变化


Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐