使用ANT构建项目实例2步骤1: build.xml

来源:互联网 发布:安川机械手编程 编辑:程序博客网 时间:2024/06/05 06:40

1. build.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<project name="IGRP" basedir="." default="war">

    <!-- import properties (app settings, classpath, jar file locations) -->
    <import file="properties.xml"/>

    <target name="init" description="defines custom tasks">
        <!-- Taskdefs -->
        <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${ant-contrib.jar}"/>
       
        <!-- Ensure that Ant 1.6.2+ is being used -->
        <available classname="org.apache.tools.ant.DynamicAttribute" property="ant-1.6.2"/>
        <fail unless="ant-1.6.2" message="IGRP requires Ant 1.6.2 for faster unit testing"/>
   
  <condition property="sync.inData">
            <equals arg1="${igrp.syncTimerSyncInData}" arg2="1"/>
        </condition>

  <condition property="message.open">
            <equals arg1="${igrp.message}" arg2="true"/>
        </condition>
 
    </target>  
   
    <!-- create target directories -->
    <target name="prepare" depends="init" description="create target directories">
     <tstamp/>
     <tstamp><format property="copyright.year" pattern="yyyy"/></tstamp>
     <echo message="Preparing target directory '${webapp.target}'"/> 
        <mkdir dir="${webapp.target}"/>
        <mkdir dir="${webapp.target}/WEB-INF"/>
        <mkdir dir="${webapp.dist}"/>
    </target>  

    <!-- 配置global-*.xml -->
    <filterset id="variables.to.replace">
  <filter token="APPNAME" value="${webapp.name}"/>

  <filter token="IGRP_DIPPERUPLOAD" value="${igrp.dipperUpload}"/>
  <filter token="IGRP_WORKFLOWUPLOAD" value="${igrp.workflowUpload}"/>
     
        <filter token="SYSTEM_ID" value="${globalconstant.systemId}"/>      
        <filter token="SYSTEM_ID_STRING" value="${globalconstant.systemIdString}"/>
        <filter token="SYSTEM_ID2" value="${dbsql.systemIdString}"/>
        <filter token="SYSTEM_NAME" value="${globalconstant.systemName}"/>
  <filter token="SYSTEM_NAME_SUFFIX" value="${globalconstant.systemName.Suffix}"/>
     
        <filter token="IGRP_JWS" value="${igrp.jws}"/>
        <filter token="IGRP_JWSURL" value="${igrp.jwsUrl}"/>
     
     <filter token="OA_VERSION" value="${igrp.OAVersion}"/>
     <filter token="OA_CLASSID" value="${igrp.OAClassID}"/>
     
        <filter token="IGRP_MDMAIL" value="${igrp.mdmail}"/>
     <filter token="IGRP_MDMAILSERVER" value="${igrp.mdmailServer}"/>
     
        <filter token="ISWITCH_URL" value="${iswitch.url}"/>     
     <filter token="IGRP_SYNCTIMERSYNCINDATA" value="${igrp.syncTimerSyncInData}"/>
  <filter token="IGRP_SYNCISPRIMARYSYSTEM" value="${igrp.syncIsPrimarySystem}"/>
     
     <filter token="IGRP_MESSAGE" value="${igrp.message}"/>
     <filter token="IGRP_MESSAGE_METHOD" value="${igrp.messageMethod}"/>
     <filter token="IGRP_MESSAGE_CONTENTSIZE" value="${igrp.messageContentSize}"/>
     <filter token="IGRP_MESSAGE_SIZE" value="${igrp.messageSendSize}"/>
     <filter token="IGRP_MESSAGE_IP" value="${igrp.messageIp}"/>
     <filter token="IGRP_MESSAGE_PORT" value="${igrp.messagePort}"/>
     <filter token="IGRP_MESSAGE_USERNAME" value="${igrp.messageUsername}"/>
     <filter token="IGRP_MESSAGE_PASSWORD" value="${igrp.messagePassword}"/>
    </filterset>
 
 <!-- 数据库属性 -->
    <filterset id="db.variables">
  <filter token="DB-DRIVERNAME" value="${database.driver_class}"/> 
        <filter token="DB-URL" value="${database.url}"/>
        <filter token="DB-NAME" value="${database.name}"/>
        <filter token="DB-USERNAME" value="${database.username}"/>
        <filter token="DB-PASSWORD" value="${database.password}"/>
     
  <filter token="MD-DB-DRIVERNAME" value="${md.database.driver_class}"/>
  <filter token="MD-DB-URL" value="${md.database.url}"/>
        <filter token="MD-DB-NAME" value="${md.database.name}"/>
        <filter token="MD-DB-USERNAME" value="${md.database.username}"/>
        <filter token="MD-DB-PASSWORD" value="${md.database.password}"/>

  <filter token="SMS-DB-DRIVERNAME" value="${sms.database.driver_class}"/>
  <filter token="SMS-DB-URL" value="${sms.database.url}"/>
        <filter token="SMS-DB-NAME" value="${sms.database.name}"/>
        <filter token="SMS-DB-USERNAME" value="${igrp.messageUsername}"/>
        <filter token="SMS-DB-PASSWORD" value="${igrp.messagePassword}"/>     
    </filterset>       
 
 <!-- 生成所有配置文件 -->
 <target name="copy-all-config" depends="prepare" description="Copy any resource and configuration files">
     <copy todir="${webapp.target}/WEB-INF/igrpConfig" includeEmptyDirs="no">
            <fileset dir="web/WEB-INF/igrpConfig">
    <include name="global-*.xml"/>    
            </fileset>
            <filterset refid="variables.to.replace"/>
        </copy>
     <if>           
            <isset property="sync.inData"/>           
   <then>
                <replace file="${webapp.target}/WEB-INF/igrpConfig/global-action.xml">
                    <replacetoken><![CDATA[<dipper-action name="timerSyncInData" starter="false">]]></replacetoken>
                    <replacevalue><![CDATA[<dipper-action name="timerSyncInData" starter="true">]]></replacevalue>
                </replace>                      
          <copy todir="${webapp.target}/WEB-INF/classes" includeEmptyDirs="no">
              <fileset dir="web/WEB-INF/classes">
      <include name="hibernate.properties"/>
              </fileset>           
     <filterset refid="db.variables"/>
          </copy>
          <copy todir="${webapp.target}/WEB-INF/classes" includeEmptyDirs="no">
              <fileset dir="web/WEB-INF/classes">
      <include name="iswitch.properties"/>
              </fileset>
              <filterset refid="variables.to.replace"/>
          </copy>
         </then>
        </if>            
        <copy todir="${gen.dir}/${webapp.name}" includeEmptyDirs="no">
            <fileset dir="web/WEB-INF/classes">
    <include name="messageResource*.properties"/>
            </fileset>
   <filterset refid="variables.to.replace"/>
        </copy>
  <native2ascii src="${gen.dir}/${webapp.name}" dest="${webapp.target}/WEB-INF/classes"
            includes="messageResource*.properties" encoding="GBK" />
    </target> 
 
 <!-- =================================================================== -->
    <!-- The "copy-web-files" target copies the static web resources portion -->
    <!-- of your web application source into the build target area           -->
    <!-- =================================================================== -->
    <target name="copy-web-files" depends="copy-all-config" description="Copy static files">
  <echo message="Copying static files"/>
  <tstamp>
            <format property="build.timestamp" pattern="yyyy年MM月dd日 HH.mm.ss EEEE"/>
        </tstamp>
        <copy todir="${webapp.target}">
            <fileset dir="web" includes="WEB-INF/jspf/foot.jspf"/>
            <filterset>
                <filter token="APPVERSION" value="${webapp.version}"/>
                <filter token="COPYRIGHT-YEAR" value="${copyright.year}"/>
                <filter token="BUILD-TIME" value="${build.timestamp} by ${user.name}"/>
            </filterset>
        </copy>
        <copy todir="${webapp.target}" includeEmptyDirs="no">
            <fileset dir="${basedir}/web">
                <include name="**"/>
    <exclude name="**/lib/**"/>
                <exclude name="**/classes/**"/>
            </fileset>
        </copy>
        <copy todir="${webapp.target}" overwrite="true" includeEmptyDirs="no">
      <fileset dir="extras/${webapp.parentpath}">
             <include name="oa/**"/>
            </fileset>
            <fileset dir="extras/${webapp.extraspath}">
             <include name="images/**"/>
            </fileset>   
        </copy>
    </target>  

    <!-- 编译Java源代码 -->
    <target name="compile-java" depends="prepare" description="alias for compile service java source"> 
  <compile module="java"/>  
 </target>
 
 <target name="package-java" depends="compile-java" description="Package service JAR"> 
  <mkdir dir="${build.dir}/java/classes/META-INF"/>
  <jar destfile="${dist.dir}/${webapp.name}-java.jar">
            <manifest>
                <attribute name="Class-Path" value="${webapp.name}-java.jar"/>
            </manifest>
            <fileset dir="${build.dir}/java/classes" includes="**/*.class"/>
         <metainf dir="${build.dir}/java/classes/META-INF"/>
        </jar>
 </target>
 
 <target name="war" depends="copy-web-files,package-java" description="Package WAR">
  <echo message="IGRP数据库 - URL: ${database.host} name: ${database.name} user: ${database.username}"/>
  <echo message="md数据库 - URL: ${md.database.host} name: ${md.database.name} user: ${md.database.username}"/>  
  <if>           
            <not><isset property="sync.inData"/></not>           
   <then>
                <echo level="info">屏蔽数据交换监听器</echo>
                <replace file="${webapp.target}/WEB-INF/web.xml">
                    <replacetoken><![CDATA[<listener> 
     <listener-class>cn.com.ivisions.interchange.client.client.ClientListener</listener-class> 
    </listener>]]></replacetoken>
                    <replacevalue><![CDATA[]]></replacevalue>
                </replace>                               
            </then>
        </if>
  <if>           
            <not><isset property="message.open"/></not>           
   <then>
                <echo level="info">屏蔽短信监听器</echo>
                <replace file="${webapp.target}/WEB-INF/web.xml">
                    <replacetoken><![CDATA[<listener> 
     <listener-class>cn.com.ivisions.message.MessageListener</listener-class> 
    </listener>]]></replacetoken>
                    <replacevalue><![CDATA[]]></replacevalue>
                </replace>                               
            </then>
        </if>
  <replaceregexp flags="g"
            file="${webapp.target}/WEB-INF/web.xml"
            match='dipper@SYSTEM_ID@'
            replace='dipper${globalconstant.systemId}'/>
  <replaceregexp flags="g"
            file="${webapp.target}/WEB-INF/web.xml"
            match='@IGRP_DIPPERUPLOAD@'
            replace='${igrp.dipperUpload}'/>
  <!-- Copy tomcat-context.xml file to ${webapp.name}.xml -->  
        <copy tofile="${gen.dir}/${webapp.name}/context.xml"
            file="metadata/conf/tomcat-context-5.5.xml" overwrite="true">
            <filterset refid="db.variables"/>
        </copy>               
  <!-- Copy files in WEB-INF to ${webapp.target}/WEB-INF -->
        <copy todir="${webapp.target}/WEB-INF">
            <fileset dir="web/WEB-INF">
                <include name="*.tld"/>
                <include name="*.xml"/>
            </fileset>
        </copy>
  <war destfile="${webapp.dist}/${webapp.war}" duplicate="preserve"
       webxml="${webapp.target}/WEB-INF/web.xml" compress="true">
   <fileset dir="${webapp.target}" excludes="**/web.xml"/>
   <metainf dir="${gen.dir}/${webapp.name}" includes="context.xml"/>           

   <lib file="${dist.dir}/${webapp.name}-java.jar"/>                                   
   <lib file="${dipper.jar}"/>
   <lib file="${OAPlugIns.jar}"/>
   <lib file="${hibernate.jar}"/>   
   <lib file="${rplum-c.jar}"/>       
  </war>
    </target>  

 <target name="copy-lib-files" description="copy jar files to tomcat"> 
  <copy todir="${tomcat.home}/common/lib">
      <fileset dir="${c3p0.dir}" includes="*.jar"/>
   <fileset dir="${castor.dir}" includes="*.jar"/>
   <fileset dir="${distributions.dir}">
                <include name="*.jar"/>
    <exclude name="rplum-c.jar"/>
            </fileset>   
   <fileset dir="${hibernate-lib.dir}" includes="*.jar"/>
   <fileset dir="${htmleditor.dir}" includes="*.jar"/>
   <fileset dir="${commons.dir}" includes="*.jar"/>
   <fileset dir="${javamail.dir}" includes="*.jar"/>
   <fileset dir="${jcom.dir}" includes="*.jar"/>
   <fileset dir="${log4jdbc.dir}" includes="*.jar"/>
   <fileset dir="${log4j.dir}/dist/lib/" includes="*.jar"/>
   <fileset dir="${mysql.dir}" includes="*.jar"/>
   <fileset dir="${OAPlugIns.dir}">
                <include name="*.jar"/>
    <exclude name="OAPlugIns.jar"/>
            </fileset>
   <fileset dir="${oracle10.dir}" includes="*.jar"/>
   <fileset dir="${slf4j.dir}" includes="*.jar"/>
   <fileset dir="${sqlserver2005.dir}" includes="*.jar"/>
        </copy>
  <copy todir="${tomcat.home}/common/classes" includeEmptyDirs="no">
            <fileset dir="web/WEB-INF/classes">
                <include name="log4j.properties"/>
            </fileset>
        </copy>  
 </target>
 
 <macrodef name="compile">
        <attribute name="module"/>
        <attribute name="additional.src.dirs" default=""/>
        <element name="options" optional="yes"/>

        <sequential>
            <echo>Compiling @{module}...</echo>
            <mkdir dir="${build.dir}/@{module}/classes"/>
            <javac srcdir="${src}/@{module};@{additional.src.dirs}"
                destdir="${build.dir}/@{module}/classes" debug="${compile.debug}"
                deprecation="${compile.deprecation}" optimize="${compile.optimize}"
                classpathref="@{module}.compile.classpath">
                <options/>
            </javac>
        </sequential>
    </macrodef>
   
    <!-- =================================================================== -->
    <!-- 数据库初始化                                                           -->
    <!-- =================================================================== -->
    <target name="db-prepare" depends="init">
        <echo message="生成数据库初始化脚本db.sql"/>
        <echo>SYSTEM_ID: ${globalconstant.systemId}</echo>
        <echo>SYSTEM_ID2: ${dbsql.systemIdString}</echo>
        <echo>SYSTEM_NAME: ${globalconstant.systemName}</echo>
        <copy tofile="${gen.dir}/${webapp.name}/db.sql" overwrite="true" filtering="true">
            <fileset file="metadata/sql/db.sql"/>
            <filterset refid="variables.to.replace"/>
        </copy>                           
    </target>
   
    <target name="db-create" depends="db-prepare"
        description="create database for ${database.type}">
        <echo level="debug">${database.jar}</echo>
        <if>
            <equals arg1="${database.type}" arg2="oracle:thin"/>
            <then>
                <echo message="Detected Oracle, importing database..."/>
                <echo>Creating '${database.name}' database with: db.sql</echo>
                <echo>URL: ${database.url}</echo>
                <sql onerror="stop"
                    driver="${database.driver_class}"
                    url="${database.url}"
                    userid="${database.username}"
                    password="${database.password}">

                    <classpath>
                     <fileset dir="${slf4j.dir}" includes="*.jar"/>
                     <pathelement location="${log4j.jar}"/>
                     <pathelement location="${log4jdbc.jar}"/>
                        <pathelement location="${oracle10.jar}"/>
                    </classpath>

                    <fileset dir="${gen.dir}/${webapp.name}">
                        <include name="db.sql"/>
                    </fileset>
                </sql>
            </then>
            <else>
                <echo level="warning">WARNING:</echo>
                <echo>请先创建Oracle数据库${database.name} </echo>
            </else>
        </if>
    </target> 
 
 <!-- =================================================================== -->
    <!-- The "deploy-web" target deploys the web application in the in the   -->
    <!-- non-war format.                                                     -->
    <!-- =================================================================== -->
    <target name="deploy-web" depends="copy-web-files" if="tomcat.home"
        description="deploy only web classes to servlet container's deploy directory">

        <echo message="Deploying web application to ${tomcat.home}/webapps"/>
        <copy todir="${tomcat.home}/webapps/${webapp.name}">
            <fileset dir="${webapp.target}"
                excludes="**/web.xml"/>
        </copy>

    </target>
 
 <!-- =================================================================== -->
    <!--            Refresh - Stops Tomcat, and refreshes everything         -->
    <!-- =================================================================== -->
    <target name="refresh" depends="undeploy,clean,deploy"
        description="Undeploys, cleans, then re-deploys"/>
 
 <!-- =================================================================== -->
    <!-- The "deploy" target deploys the web application by packaging it as  -->
    <!-- a WAR and then unpackaging it into Tomcat's webapps directory       -->
    <!-- =================================================================== -->
    <target name="deploy" depends="copy-lib-files,war" if="tomcat.home"
        description="unwar into the servlet container's deployment directory">

        <unwar src="${webapp.dist}/${webapp.war}"
            dest="${tomcat.home}/webapps/${webapp.name}"/>

    </target>
 
 <!-- =================================================================== -->
    <!-- The "undeploy" target deletes the web application archive and the   -->
    <!-- web application directory in the compatible servlet container.      -->
    <!-- =================================================================== -->
    <target name="undeploy" if="tomcat.home"
        description="undeploy war file to servlet container's deployment dir">
        <echo message="Undeploying webapp from Tomcat"/>
        <delete file="${tomcat.home}/webapps/${webapp.war}"/>
        <delete dir="${tomcat.home}/webapps/${webapp.name}"/>
    </target>

    <!-- =================================================================== -->
    <!-- The "deploy-war" deploys the web application in the in a war format -->
    <!-- =================================================================== -->
    <target name="deploy-war" depends="copy-lib-files,war" if="tomcat.home"
        description="Deploy '${webapp.name}.war' to local Tomcat">
        <copy file="${webapp.dist}/${webapp.war}"
            todir="${tomcat.home}/webapps"/>
    </target>
 
 <!-- =================================================================== -->
    <!--            Setup Tomcat                                             -->
    <!-- ===================================================================
    <target name="setup-tomcat" depends="init" if="tomcat.home" description="copies context.xml to tomcat">
        <echo message="Detected Tomcat 5.5..."/>
        <echo level="info">Copying ${webapp.name}.xml...</echo>
        <copy tofile="${tomcat.home}/conf/Catalina/localhost/${webapp.name}.xml"
            file="metadata/conf/tomcat-context-5.5.xml" overwrite="true">
            <filterset refid="db.variables"/>
        </copy>               
    </target>-->  
 
 <!-- =================================================================== -->
    <!--            Convenience target to setup everything                   -->
    <!-- ===================================================================
    <target name="setup" depends="deploy"
        description="Sets up tomcat and deploys expanded war">   
 </target>-->
 
 <!-- Remove classes directory for clean build -->
    <target name="clean" description="Removes build artifacts">
        <echo level="info">Cleaning build and distribution directories</echo>
        <delete dir="${build.dir}"/>
        <delete dir="${dist.dir}"/>
  <delete dir="${gen.dir}"/>
    </target>

</project>

 

原创粉丝点击