`

ant demo bak 2010-02-22

    博客分类:
  • Ant
阅读更多

ANT demo project

 

 

<?xml version="1.0" encoding="UTF-8"?>
<project default="rebuild" name="user">

    <description>
        test ant build *.war file
    </description>

    <!--1.定义变量  ################################################################-->
    <property name="author" value="san" />
    <property name="java_src_dir" value="src" />
    <property name="class_dest_dir" value="class" />
    <property name="jar_dest_dir" value="WebContent/WEB-INF/lib" />
    <property name="jar_fileName" value="demo.jar" />


    <!-- 指定环境变量对象为:SystemVariable -->
    <property environment="SystemVariable" />
    <!-- 将tomcat.home指向环境变量TOMCAT_HOME指向的路径 -->
    <property name="tomcat.home" value="${SystemVariable.TOMCAT_HOME}" />

    <!-- 设置*.war 文件的部署及文件名  -->
    <property name="warName" value="demo.war" />
    <property name="wardir_and_fileName" value="${tomcat.home}/webapps/${warName}" />

    <!-- 执行javac命令时,需要文件路径参数,类似环境变量中的classpath -->
    <path id="classpath">
        <pathelement location="${java_src_dir}" />
        <pathelement location="${class_dest_dir}" />
        <fileset dir="${jar_dest_dir}" includes="**/*.jar" />
    </path>
    <!--  定义变量  end ################################################################-->

    <!--2.创建需要的文件夹
    -->
    <target name="init" description="test initialization">
        <mkdir dir="${class_dest_dir}" />
    </target>

    <!--  3.编译src目录下的*.java为*.class
    -->
    <target name="compile" depends="init">
        <!-- 解决调用jar包中类时,出现中文乱码的问题:在此标签中加入:encoding="UTF-8"  -->
        <javac srcdir="${java_src_dir}" destdir="${class_dest_dir}" encoding="UTF-8" deprecation="on" debug="on">
            <classpath refid="classpath" />
        </javac>
    </target>

    <!--  4.将*.class打包为*.jar文件 
    -->
    <target name="build" depends="compile">
        <jar destfile="${jar_dest_dir}/${jar_fileName}" basedir="${class_dest_dir}">
            <manifest>
                <attribute name="Build-By" value="${author}" />
            </manifest>
        </jar>
        <ant target="clean_classes" antfile="build.xml" />
    </target>
    <!--  9.清除*.class文件 
    -->
    <target name="clean_classes">
        <delete dir="${class_dest_dir}" />
    </target>

    <!-- 10.清除*.jar 文件 
    -->
    <target name="clean_jar">
        <delete file="${jar_dest_dir}/${jar_fileName}" />
    </target>

    <!-- 11.重新构造jar文件 
    -->
    <target name="rebuild" depends="clean_classes,clean_jar,build" />

    <!--  打包*.war文件 
    -->
    <target name="war">
        <jar jarfile="${wardir_and_fileName}">
            <fileset dir="WebContent">
                <include name="**/*" />
            </fileset>
        </jar>
    </target>

    <!--  运行方法 
    -->
    <target name="run">
        <java classname="org.taink.test.TestClass" classpath="${jar_dest_dir}/${jar_fileName}" />
    </target>


    <!-- ================================================================================== -->
    <!-- 指定环境变量参数为:SystemVariable
    <property environment="SystemVariable" />
    -->
    <!-- 将tomcat.home指向环境变量TOMCAT_HOME指向的路径
    <property name="tomcat.home" value="${SystemVariable.TOMCAT_HOME}" />
    -->
    <!-- 测试:输出tomcat 的物理路径
    <target name="display">
        <echo message="${tomcat.home}" />
    </target>   
    -->

    <!-- 删除tomcat目录下的文件夹 
    <target name="delete_pro">
        <echo message="delete dir :${tomcat.home}/webapps/demo"></echo>
        <delete file="${tomcat.home}/webapps/demo" />
    </target>
    -->
    <!-- 5.将java源打包为*.jar
    <target name="buildSrcJar">
        <jar destfile="flexdata-src.jar" basedir="${java_src_dir}">
            <manifest>
                <attribute name="Build-By" value="${author}" />
            </manifest>
        </jar>
    </target>
    -->

    <!-- 6.清除java源*.jar
    <target name="cleanSrcJar">
        <delete file="flexdata-src.jar" />
    </target>
    -->

    <!-- 7.将*.java打包为.zip文件 
    <target name="buildZip">
        <zip destfile="flexdata.zip" basedir="${java_src_dir}" />
    </target>
    -->

    <!-- 8.清除 *.zip文件 
    <target name="cleanZip">
        <delete file="flexdata.zip" />
    </target>
    -->


    <!-- 11.重新构造jar文件 
    <target name="rebuild" depends="clean_classes,clean_jar,build" />
    -->

    <!-- 12.重新构造jar文件(另一写法)
    <target name="rebuild2">
        <ant target="clean_classes" antfile="build.xml" />
        <ant target="clean_jar" antfile="build.xml" />
        <ant target="build" antfile="build.xml" />
    </target>
    -->

    <!-- ================================================================================== -->

</project>

 

***********************************************************************************************

 

 

 

<?xml version="1.0" encoding="UTF-8"?>
<project default="rebuild" name="user">

    <description>
        jtosa project
    </description>

    <!-- declare variable -->
    <property name="author" value="TianTong" />
    <property name="java_src_dir" value="src" />
    <property name="class_dest_dir" value="class" />
    <property name="jar_dest_dir" value="WebApp/WEB-INF/lib" />
    <property name="jar_fileName" value="jtosa.jar" />

    <property environment="SystemVariable" />

    <property name="tomcat.home" value="${SystemVariable.TOMCAT_HOME}" />

    <property name="warName" value="jtosa.war" />
    <property name="war_dest_dir" value="${tomcat.home}/webapps" />
    <property name="war_dest_dir_and_fileName" value="${war_dest_dir}/${warName}" />

    <path id="classpath">
        <pathelement location="${java_src_dir}" />
        <pathelement location="${class_dest_dir}" />
        <fileset dir="${jar_dest_dir}" includes="**/*.jar" />
    </path>


    <!-- operation -->
    <target name="init" description="test initialization">
        <mkdir dir="${class_dest_dir}" />
    </target>

    <target name="compile" depends="init">
        <javac srcdir="${java_src_dir}" destdir="${class_dest_dir}" encoding="UTF-8" deprecation="on" debug="on">
            <classpath refid="classpath" />
        </javac>
    </target>

    <target name="clean_class_dir">
        <delete dir="${class_dest_dir}" />
    </target>
   
    <target name="build" depends="compile">
        <jar destfile="${jar_dest_dir}/${jar_fileName}" basedir="${class_dest_dir}">
            <manifest>
                <attribute name="Build-By" value="${author}" />
            </manifest>
        </jar>
        <ant target="clean_class_dir" antfile="build.xml" />
    </target>


    <target name="clean_jar">
        <delete file="${jar_dest_dir}/${jar_fileName}" />
    </target>

    <target name="rebuild" depends="clean_class_dir,clean_jar,build" />

    <target name="deploy" depends="build">
        <jar jarfile="${war_dest_dir_and_fileName}">
            <fileset dir="WebApp">
                <include name="*" />
                <include name="**/*" />
            </fileset>
        </jar>
    </target>
   
    <target name="redeploy" depends="build">
        <ant target="deleteFile" antfile="build.xml" />
        <ant target="deploy" antfile="build.xml" />
    </target>
   
    <target name="deleteFile">
        <echo message="delete file: ${war_dest_dir_and_fileName}" />
        <delete file="${war_dest_dir_and_fileName}" />
    </target>
   
    <!--
        <delete dir="${war_dest_dir}/jtosa" />
    -->

</project>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics