jenkins ant + SVN + tomcat package deployment

This article does not talk from the most basic, please according to other articles, such as maven compile, modify.

There are many ways Jenkins compilation, many of which are using the Web to find the maven compile, ant way rarely, ant way need not rely on maven.

Here I can only say that the focus, and if in doubt problems can e-mail contact [email protected] I'll give you a solution at the time of leisure

Highlights

1, the installation jenkins

When first installed, due to network reasons, will be stuck in jenkins is starting., URL mirrored stations in hudson.model.UpdateCenter.xml in place jenkins home directory. (This problem is simply pit ...... God, I saw victims as well as GC tomcat log log ......)

<?xml version='1.1' encoding='UTF-8'?>
<sites>
  <site>
    <id>default</id>
    <url>http://mirror.xmission.com/jenkins/updates/update-center.json</url>
  </site>
</sites>

2, jenkins version selection

We recommended to select a new stable version, but the new version requires JDK1.8 support.

3, ant compile way corresponds to bulid file (the most important step)

The following files are based on the actual situation changes, we need to create some paths in advance, please error completion according to jenkins compile time.

<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="deploy" basedir="/root/.jenkins/workspace/test">
	<property environment="env" />
	<property name="webapp.name" value="test" />
	<property name="catalina.home" value="/usr/local/tomcat/" />
	<property name="dist.dir" value="${basedir}/dist" />
	<property name="ant.dir" value="/usr/local/ant-1.9.13" />
	<property name="webRoot.dir" value="${basedir}/WebRoot" />
	<property name="src.dir" value="${basedir}/src" />
	<property name="config.dir" value="${basedir}/src" />
	<property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" />
	<property name="build.dir" value="${basedir}/build" />
	<!-- 使用eclipse jdt进行编译,而不使用JDK编译  -->
	<!-- <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" />  -->
	<!-- <property name="build.compiler" value="D:\MyWorkApps\Java\jdk1.8.0_51" /> -->
 
	<!-- 初始化classpath -->
	<path id="project.classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
		<!-- 添加tomcat类路径 -->
		<fileset dir="${catalina.home}/lib">
			<include name="*.jar" />
		</fileset>
		<!-- ant lib包  -->
		<fileset dir="${ant.dir}">
			<include name="**/*.jar" />
		</fileset>
	</path>
 
	<!-- get the source compile classpath in a printable form -->
	<pathconvert pathsep="${line.separator}|   |-- "
             property="echo.path.compile"
             refid="project.classpath">
	</pathconvert>
	
	<!-- show classpath jars -->
	<target name="print_classpath">
		<echo message="|-- compile classpath"/>
		<echo message="|   |"/>
		<echo message="|   |-- ${echo.path.compile}"/>
	</target>
	
	
	<!-- 删除之前的目录结构 -->
	<target name="clear" description="清理旧文件">
		<delete dir="${build.dir}" />
		<!--<delete dir="${dist.dir}" />-->
		<delete file="${catalina.home}/webapps/${webapp.name}.war" />
		<delete dir="${catalina.home}/webapps/${webapp.name}" />
	</target>
 
	<!-- 创建目录结构 -->
	<target name="init" depends="clear" description="创建初始化目录结构">
		<mkdir dir="${build.dir}/classes" />
		<mkdir dir="${dist.dir}" />
	</target>
 
	<!-- 编译java -->
	<target name="compile" depends="init" description="编译java文件">
		<echo message="begin compile..." />
		<javac srcdir="${src.dir}" destdir="${build.dir}/classes" 
			includeantruntime="false" nowarn="on" 
			source="1.7" target="1.7" deprecation="true" debug="true" 
			encoding="UTF-8" classpathref="project.classpath" 
			>
			<compilerarg line="-Xlint:unchecked" />
			<!-- <classpath refid="project.classpath" /> -->
		</javac>
		
		<copy todir="${build.dir}/classes">
			<fileset dir="${src.dir}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
				<include name="**/*.sql" />
			</fileset>
			<!--<fileset dir="${config.dir}">
				<include name="**/*.xml" />
				<include name="**/*.properties" />
				<include name="**/*.sql" />
			</fileset>--> 
		</copy>
		
		<echo message="end compile..." />
	</target>
 
	<!-- 将class文件打成 jar包 -->
	<!--  
	    <target name="pack" depends="compile"> 
	        <jar jarfile="${build.dir}/${webapp.name}.jar"> 
	            <fileset dir="${build.dir}/classes"> 
	                <include name="**/*.class"/> 
	            </fileset> 
	        </jar> 
	    </target> 
	-->
 
	<!-- 打成war包, 名称默认为 项目名 -->
	<target name="war" depends="compile" description="将工程打成war包">
		<echo message="begin war..." />
		<war destfile="${dist.dir}/${webapp.name}.war" basedir="${webRoot.dir}" webxml="${webRoot.dir}/WEB-INF/web.xml">
			<lib dir="${lib.dir}" />
			<classes dir="${build.dir}/classes" />
			<fileset dir="${webRoot.dir}">
				<include name="***.*" />
			</fileset>
		</war>
		<echo message="end war..." />
	</target>
 
	<!-- copy war包 tomcat的deploy目录 -->
	<target name="deploy" depends="war" description="部署项目">
		<echo message="begin deploy..." />
		<copy file="${dist.dir}/${webapp.name}.war" todir="/tmp/war/webapps" />
		<echo message="end deploy..." />
	</target>
	
 
</project>

4, bulid file path

If bulid file path, not in the project root path may establish a path

Published 26 original articles · won praise 1 · views 7256

Guess you like

Origin blog.csdn.net/chinazzb/article/details/85337841