WalkingWithJava

我相信人生是值得活的,尽管人在一生中必须遭受痛苦,卑劣,残酷,不幸和死亡的折磨,我依然深信如此.但我认为人生不一定要有意义,只是对一些人而言,他们可以使人生有意义.------J 赫胥黎...

Ant 常用Task

Installation:

 

1. Set the ANT_HOME environment variable to point to this location.

 

2. Set the JAVA_HOME environment variable to point to the JDK location.

 

3. Add ANT_HOME/bin to your system's PATH environment variable.

 

Build file :

 

1.     ${build.dir} means referenced a var :build.dir

 

 

 

2.     specify diretory :

 

<property name="src.dir" value="src"/>

 

  <!-- Temporary build directories -->

 

  <property name="build.dir" value="build"/>

 

 

 

3.     make dir on specified diretory :

 

  <target name="prepare">

 

    <mkdir dir="${build.lib}"/>

 

  </target>

 

 

 

4.     clean dir

 

  <target name="clean" description="Remove all generated files.">

 

    <delete dir="${build.dir}"/>

 

  </target>

 

 

 

5.     compile java files

 

  <target name="compile" depends="prepare"

 

          description="Compiles all source code.">

 

<javac srcdir="${src.dir}"

 

destdir="${build.classes}"/>

 

  </target>

 

 

 

6.     jar java files

 

  <target name="jar" depends="compile"

 

          description="Generates oreilly.jar in the 'dist' directory.">

 

    <!-- Exclude unit tests from the final JAR file -->

 

    <jar jarfile="${build.lib}/oreilly.jar"

 

         basedir="${build.classes}"

 

         excludes="**/*Test.class"/>

 

  </target>

 

 

 

7.     target can be invoked single : eg.

 

command line : ant jar

 

 

 

8.     specify classpath and compile :

 

<path id="mypath">

 

<pathelement location="${java.home}/jre/lib/rt.jar"/>

 

</path>

 

<target name="all">

 

<javac srcdir=".">

 

<classpath refid="mypath"/>

 

</javac>

 

</target>

 

or

 

<path id="classpath">

 

<fileset dir="${lib.dir}">

 

<include name="**/*.jar"/>

 

</fileset>

 

</path>

 

 

 

9.     copy files

 

<copy todir="${weblogic.dir}/${weblogic.server.home}/public_html/jsp">

 

<fileset dir="${src.www.dir}/jsp"/>

 

</copy>

 

 

 

10Javadoc

 

<target name = “javadoc” depends=”compile,jar”>

 

    <mkdir dir = “${doc.dir}/api”/>

 

    <javadoc packagenames = “ myproj.*”

 

        sourchpath = “${src.dir}”

 

        destdir = “${doc.dir}/api”

 

        author = “true”

 

        version = “true”

 

       use = “true”>

 

    <classpath refid = “classpath”/>

 

    </javadoc>

 

</target>

 

 

 

all in a build.xml file:

 

 

 

<?xml version="1.0"?>

 

 

 

<!-- build.xml - a simple Ant buildfile -->

 

<project name="Simple Buildfile" default="compile" basedir=".">

 

 

 

  <!-- The directory containing source code -->

 

  <property name="src.dir" value="src"/>

 

 

 

  <!-- Temporary build directories -->

 

  <property name="build.dir" value="build"/>

 

  <property name="build.classes" value="${build.dir}/classes"/>

 

  <property name="build.lib" value="${build.dir}/lib"/>

 

 

 

  <!-- Target to create the build directories prior to the -->

 

  <!-- compile target. -->

 

  <target name="prepare">

 

    <mkdir dir="${build.dir}"/>

 

    <mkdir dir="${build.classes}"/>

 

    <mkdir dir="${build.lib}"/>

 

  </target>

 

 

 

  <target name="clean" description="Remove all generated files.">

 

    <delete dir="${build.dir}"/>

 

  </target>

 

 

 

  <target name="compile" depends="prepare"

 

          description="Compiles all source code.">

 

    <javac srcdir="${src.dir}" destdir="${build.classes}"/>

 

  </target>

 

 

 

  <target name="jar" depends="compile"

 

          description="Generates oreilly.jar in the 'dist' directory.">

 

    <!-- Exclude unit tests from the final JAR file -->

 

    <jar jarfile="${build.lib}/oreilly.jar"

 

         basedir="${build.classes}"

 

         excludes="**/*Test.class"/>

 

  </target>

 

 

 

  <target name="all" depends="clean,jar"

 

          description="Cleans, compiles, then builds the JAR file."/>

 

 

 

</project>

 

 

 

阅读更多
个人分类: 历史备份
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

Ant 常用Task

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭