自动构建的脚本

来源:互联网 发布:gulp 知乎 编辑:程序博客网 时间:2024/05/16 12:32

开发过程中,根据持续构建的原则,必须要达到自动构建。

自动构建代码的运行过程:

1.从scm库取得源代码。

2.从scm库的work2_tomcat分支取得tomcat版本代码

3.用tomcat版本代码替换scm库中相应配置。

4.用user_submit目录下开发人员的代码替换scm库中相应的代码。

5.编译。

6.拷贝编译好的到dist目录。

使用:

1.安装ant和cvs客户端,并将cvs.exe的目录加入Path变量。

2.编辑build.properties,用自己的用户名和密码替换。

3.将自己开发的程序按照wsad的目录结构,拷贝到user_submit目录下。

4.进入到build.xml所在目录,在命令行敲入ant。

5.进入dist目录,将里面的内容拷贝到tomcat的发布根目录。

自动构建的脚本

build.xml

<project name="myproj" default="all" basedir=".">

<property file="${basedir}/build.properties" />
<!-- set global properties for this build -->
<property name="scm" value="scm/work2"/>
<property name="scm.project.root" value="${scm}/scm/work2"/>
<property name="scm.src" value="${scm.project.root}/JavaSource"/>
<property name="scm.web" value="${scm.project.root}/WebContent"/>

<property name="tomcat" value="tomcat/work2"/>
<property name="tomcat.tag" value="work2_tomcat"/>

<property name="user.submit.path" value="user_submit"/>

<property name="build" value="${scm.web}/WEB-INF/classes"/>
<property name="dist" value="dist"/>

    <property name="cvsroot" value=":pserver:${cvs.user}:${cvs.password}@${cvs.server}:${cvs.repository}"/>
   
 
    <property name="main.dir" value="${scm}"/>
    <property name="main.cvs.repository.path" value="${scm}"/>
  
    <property name="tomcat.dir" value="${tomcat}"/>
    <property name="tomcat_tag.cvs.repository.path" value="${tomcat}"/>


  
    <!-- Initializing -->
    <target name="init">
        <tstamp>
            <format property="today" pattern="yyyy-MM-dd hh:mm:ss"/>
        </tstamp>
        <echo message="${today}" />
       
       
       
    </target>
    <!-- 捡出主干程序 -->
  <target name="main-check-out" depends="init">
   <echo message="捡出主干程序" />
    <mkdir dir="${scm.project.root}"/>
        <cvs cvsRoot="${cvsroot}" package="${main.cvs.repository.path}"  dest="${main.dir}"/>
    </target>
    <!-- 捡出tomcat分支程序 -->
   <target name="tomcat-tag-check-out" depends="init">
   <echo message="捡出tomcat分支程序" />
     <mkdir dir="${tomcat}"/>
        <cvs cvsRoot="${cvsroot}" package="${main.cvs.repository.path}" tag="${tomcat.tag}" dest="${tomcat.dir}"/>
    </target>
    <!-- 合并tomcat分支程序 -->
    <target name="merge-tomcat" depends="main-check-out,tomcat-tag-check-out">
    <echo message="合并tomcat分支程序" />
     <copy todir="${main.dir}"  verbose="yes" overwrite="true">
    <fileset dir="${tomcat.dir}" />
   </copy>
    </target>
        <!-- 合并用户提交程序 -->
    <target name="merge-user-submit">
     <echo message="合并新开发程序" />
     <copy todir="${scm.project.root}" verbose="yes" overwrite="true">
    <fileset dir="${user.submit.path}" />
   </copy>
    </target>
   
<target name="compile" depends="init">
<!-- Compile the java code from ${src} into ${build} -->
<echo message="编译" />
<delete dir="${build}"/>
<mkdir dir="${build}"/>
<echo message="build src:${scm.src}/ndestdir:${build}" />
<javac srcdir="${scm.src}" destdir="${build}" encoding="UTF-8" source="1.4"
 fork="true" memoryMaximumSize="512M">

 <classpath>
    <fileset dir="${basedir}">
        <include name="${scm.web}/WEB-INF/lib/*.jar"/>
        <include name="lib/*.jar"/>
      </fileset>
   <pathelement path="${java.class.path}/"/>
</classpath>
</javac>
    <copy toDir="${build}">
      <fileset dir="${scm.src}"
        includes=
        "**/*.properties,**/*.xml"/>
    </copy>
</target>

<target name="dist">
<!-- Create the distribution directory -->
<echo message="构建程序到${dist}目录" />
   <mkdir dir="${dist}"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->

   <copy todir="${dist}">
    <fileset dir="${scm.web}" />
   </copy>
</target>
<target name="all" depends="clean,merge-tomcat,merge-user-submit,compile,dist">
</target>
<target name="clean">
<!-- Delete the ${build} and ${dist} directory trees -->
  
  <delete dir="${dist}"/>
        <delete dir="${scm.project.root}"/>
 
        <delete dir="${tomcat}"/>
       

</target>

    <target name="create-war-file">
        <echo message="正在打包应用程序..." />
        <war destfile="${tomcat.home}/webapps/kpi.war"
            basedir="${dist}" webxml="${dist}/WEB-INF/web.xml">
        </war>
    </target>
    <target name="create-war-file-kmss">
        <echo message="正在打包应用程序..." />
        <war destfile="${tomcat.home}/webapps/kmss_hr_pm.war"
            basedir="${dist}" webxml="${dist}/WEB-INF/web.xml">
        </war>
    </target>

</project>

build.properties:

#

user.submit.path=user_submit


cvs.user=cvsor
cvs.password=sun05
cvs.server=192.168.0.6
cvs.repository=d:/data

原创粉丝点击