日期:2014-05-19  浏览次数:20615 次

ant-j2ee例子
<?xml version="1.0" encoding="UTF-8" ?>
<project name="NES" default="doc">
    <property name="NES.home" value="." />
    <!-- 源jsp文件地址 -->
    <property name="jsp.dir" value="${NES.home}/WebRoot" />
    <!-- 源java文件地址 -->
    <property name="java.dir" value="${NES.home}/src" />
    <!-- 最终发布文件地址 -->
    <property name="dist.dir" value="${NES.home}/dist" />      
    <!-- 最终class文件地址 -->
    <property name="classes.dir" value="${NES.home}/dist/WEB-INF/classes" />   
    <!-- 最终jar文件地址 -->  
    <property name="jar.dir" value="${NES.home}/jar" />
	<property name="Name" value="${NES.home}"/>
	<property name="packages" value="classloader.*,demo.*,servlet.*"/>
    <property name="lib.dir" value="lib" />
    <property name="dist.dir" value="dist" />
    <property name="doc.dir" value="doc"/>
    
    <!-- 定义classpath -->
    <path id="master-classpath">
        <fileset file="${NES.home}/WebRoot/WEB-INF/lib/*.jar" />
        <pathelement path="${classes.dir}"/>
    </path>

    <!-- 初始化 -->
    <target name="init">
        <delete dir="${jar.dir}"/>
        <delete dir="${dist.dir}"/>
        <mkdir dir="${jar.dir}" />
        <mkdir dir="${dist.dir}" />
        <mkdir dir="${classes.dir}" />        
        <mkdir dir="${doc.dir}" />        
    </target>
    <!-- 编译 -->
    <target name="compile" depends="init" description="compile the source files">
        <javac srcdir="${java.dir}" destdir="${classes.dir}" target="1.6" includeantruntime="on" >
          
            <classpath refid="master-classpath" />
        </javac>    
    </target>
    <!-- 测试 -->
    <target name="test" depends="compile" description="run junit test">
    </target>
    <!-- 打包 -->
    <target name="pack" depends="test" description="make .jar file">
        <copy todir="${dist.dir}/WEB-INF/classes" preservelastmodified="true">
            <fileset dir="${java.dir}" >
                <include name="**/**"/>
                <include name="**.**"/>
                <exclude name="demo/**.java"/>
                <exclude name="servlet/**.java"/>
            </fileset>
        </copy>
        <copy todir="${dist.dir}" preservelastmodified="true">
            <fileset dir="${jsp.dir}" >
                <include name="**/**"/>
                <include name="**.**"/>
                <exclude name="classes/**"/>
            </fileset>
        </copy>
        <jar destfile="${jar.dir}/nes.jar" basedir="${dist.dir}" />
    </target>
    
    <!-- =================================================================== -->
  <!-- 创建文档,生成相应的api文档                                   -->
  <!-- =================================================================== -->
  <target name="doc" depends="pack">
    <mkdir dir="${build.javadocs}"/>
    <javadoc packagenames="${packages}"
             sourcepath="${classes.dir}"
             destdir="${doc.dir}"
             author="true"
             version="true"
             use="true"
             splitindex="true"
             windowtitle="${Name} API"
             doctitle="${Name}">
      <classpath refid="master-classpath"/>
    </javadoc>
  </target>
    
</project>