我的第一个 ant build.xml文件配置

ant的基本语法很简单,功能很强大ing

<?xml version="1.0" encoding="utf-8"?>
<project name="eq" default="wars" basedir=".">

    <property name="model" value="eq" />
    <property name="disk" value="disk" />
    <property name="web" value="web" />
    <property name="webinf" value="WEB-INF" />
    <property name="build" value="build"/>
    <property name="classes" value="WEB-INF/classes"/>
    <property name="lib" value="WEB-INF/lib"/>
    <property name="jsp" value="WEB-INF/web"/>
    <property name="dbimport" value="WEB-INF/dbimport"/>
    <property name="include" value="include" />
    <property name="skins" value="skins" />
    <property name="styles" value="styles" />
    <property name="cmsclasses" value="swike-cms.src" />
    <property name="templet" value="WEB-INF/templet/admin" />
    
    
    
    <!-- 指定环境变量参数为:SystemVariable -->
    <property environment="SystemVariable" />
    <!-- 将tomcat.home指向环境变量TOMCAT_HOME指向的路径 -->
    <property name="tomcat.home" value="${SystemVariable.TOMCAT_HOME}" />    
    
    
    
    <!-- 删除build路径-->
    <target name="clean">
       <delete dir="build"/>
    </target>

    <target name="init" depends="clean">
       <mkdir dir="${disk}"/>
       <mkdir dir="${build}"/>
       <mkdir dir="${webinf}"/>
       <mkdir dir="${build}/${web}"/>
       <mkdir dir="${build}/${lib}"/>
       <mkdir dir="${build}/${jsp}"/>
       <mkdir dir="${build}/${classes}"/>
       <mkdir dir="${build}/${dbimport}"/>
       <mkdir dir="${build}/${include}"/>
       <mkdir dir="${build}/${skins}"/>
       <mkdir dir="${build}/${styles}"/>
       <mkdir dir="${build}/${webinf}/${cmsclasses}"/>
       <mkdir dir="${build}/${templet}"/>
    </target>
    
    <target name="jarbao" depends="init">
        <!-- 拷贝 include -->
         <copy todir="${build}/${include}">
            <fileset dir="${include}">
                <include name="**/*.*" />
            </fileset>
        </copy>
        <!-- 拷贝 skins -->
         <copy todir="${build}/${skins}">
            <fileset dir="${skins}">
                <include name="**/*.*" />
            </fileset>
        </copy>
        <!-- 拷贝 styles -->
         <copy todir="${build}/${styles}">
            <fileset dir="${styles}">
                <include name="**/*.*" />
            </fileset>
        </copy>
         <!-- 拷贝 当前目录下的文件 -->
         <copy todir="${build}">
            <fileset dir=".">
                <include name="index.do" />
                <include name="index.ftl" />
            </fileset>
        </copy>
        
        <!-- 拷贝 当前目录下的文件 -->
         <copy todir="${build}/${templet}">
            <fileset dir="${templet}">
                <include name="*.ftl" />
            </fileset>
        </copy>
    
        <!-- 拷贝jar包到lib目录下 -->
         <copy todir="${build}/${lib}">
            <fileset dir="${lib}">
                <include name="*.jar" />
            </fileset>
        </copy>
        
        <!-- 拷贝jsp文件到web/eq目录下 -->
         <copy todir="${build}/${jsp}">
            <fileset dir="WEB-INF/web">
                <include name="**/*.jsp" />
            </fileset>
        </copy>
        <!-- WEB-INF下配置文件拷贝到-->
        <copy todir="${build}/${webinf}">
            <fileset dir="${webinf}">
                <include name="deploy.bat" />
                <include name="mytags.tld" />
                <include name="SeenService.wsdd" />
                <include name="server-config.wsdd" />
                <include name="struts-tags.tld" />
                <include name="urlrewrite.xml" />
            </fileset>
        </copy>
        <!-- 拷贝${build}/${dbimport}目录下 -->
         <copy todir="${build}/${dbimport}">
            <fileset dir="${dbimport}">
                <include name="*.xml" />
            </fileset>
        </copy>
        <!-- 配置文件拷贝到 classes根目录下 -->
        <copy todir="${build}/${classes}">
            <fileset dir="${classes}">
                <include name="*.properties" />
                <include name="*.xml" />
                <include name="*.dic" />
            </fileset>
        </copy>
       <!-- ******  -->
        <path id="lib">
            <fileset dir="WEB-INF\lib"> 
                <include name="*.jar"/>
            </fileset>
            <fileset dir="${tomcat.home}\lib"> 
                <include name="*.jar"/>
            </fileset>
        </path>
        <!-- 编译 -->
        <javac srcdir="${cmsclasses}" destdir="${build}/${webinf}/${cmsclasses}"> 
            <classpath refid="lib"></classpath>
        </javac>
        
        <!-- web下的所有 -->
        <copy todir="${build}/${web}">
            <fileset dir="web">
                <include name="**/*.*" />
            </fileset>
        </copy>
        
        <!-- 直接把eclipse编译好的 class文件 打 jar包 -->
        <jar jarfile="${build}/WEB-INF/lib/swaip-eq.jar" basedir="${classes}">
            <include name="com/**/*.class" />
        </jar>
        
    </target>
    
    <!-- 打war包-->
    <target name="wars" depends="jarbao">
        <war destfile="${disk}/eq.war" webxml="WEB-INF/web.xml">
            <fileset dir="${build}" includes="**/*.*"/>
        </war>
    </target>
    
</project>

ant

相关推荐