编译工具,速度快。在build。xml中设置相应的classpath和编译的目录已经class的目录等运行就可以实现编译。相对jbuild的编译,速度有很大的提升。

解决方案 »

  1.   

    和resin不一样的,ant 是jakarta(www.apache.org)的一个编译工具,你可以去网站上看看。下边是摘抄的一段介绍:Ant是一种基于Java的build工具。理论上来说,它有些类似于(Unix)C中的make ,但没有make的缺陷。既然我们已经有了make, gnumake, nmake, jam以及其他的build工具为什么还要要一种新的build工具呢?因为Ant的原作者在多种(硬件)平台上开发软件时,无法忍受这些工具的限制和不便。类似于make的工具本质上是基于shell(语言)的:他们计算依赖关系,然后执行命令(这些命令与你在命令行敲的命令没太大区别)。这就意味着你可以很容易地通过使用OS特有的或编写新的(命令)程序扩展该工具;然而,这也意味着你将自己限制在了特定的OS,或特定的OS类型上,如Unix。Makefile也很可恶。任何使用过他们的人都碰到过可恶的tab问题。Ant的原作者经常这样问自己:“是否我的命令不执行只是因为在我的tab前有一个空格?!!”。类似于jam的工具很好地处理了这类问题,但是(用户)必须记住和使用一种新的格式。Ant就不同了。与基于shell命令的扩展模式不同,Ant用Java的类来扩展。(用户)不必编写shell命令,配置文件是基于XML的,通过调用target树,就可执行各种task。每个task由实现了一个实现了特定Task接口的对象来运行。(如果你对Ant一点概念都没有的话,可能看不懂这一节,没有关系,后面会对target,task做详细的介绍。你如果没有太多的时间甚至可以略过这一节,然后再回来浏览一下这里的介绍,那时你就会看懂了。同样,如果你对make之类的工具不熟悉也没关系,下面的介绍根本不会用到make中的概念。)必须承认,这样做,在构造shell命令时会失去一些特有的表达能力。如`find . -name foo -exec rm {}`,但却给了你跨平台的能力-你可以在任何地方工作。如果你真的需要执行一些shell命令,Ant有一个<exec> task,这个task允许执行特定OS上的命令。
      

  2.   

    上文是ANT官方文档开头的介绍的翻译:楼上的已经把ANT的功能说的很清楚了,这里举一个简单的例子:build.xml文件内容:<project name="MyProject" default="dist" basedir=".">   工程名,基准目录为当前目录
        <description>
            simple example build file
        </description>
      <!-- set global properties for this build -->
      <property name="src" location="src"/>         源文件(.java文件)目录为当前目录下的src目录
      <property name="build" location="build"/>  编译后的文件(.class文件)放置在当前目录下的build目录(会自动创建的)
      <property name="dist"  location="dist"/>   生成的JAR包的放置目录为当前目录下的dist目录(会自动创建)  <target name="init">        init阶段工作是创建build目录
        <!-- Create the time stamp -->
        <tstamp/>
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}"/>
      </target>  <target name="compile" depends="init"  compile阶段工作在init后,完成编译源文件的工作,编译好的文件放在build目录下
            description="compile the source " >
        <!-- Compile the java code from ${src} into ${build} -->
        <javac srcdir="${src}" destdir="${build}"/>
      </target>  <target name="dist" depends="compile"   dist阶段工作在compile后,完成dist/lib目录的创建,生成JAR包
            description="generate the distribution" >
        <!-- Create the distribution directory -->
        <mkdir dir="${dist}/lib"/>    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
        <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
      </target>  <target name="clean"                  做一些清除工作
            description="clean up" >
        <!-- Delete the ${build} and ${dist} directory trees -->
        <delete dir="${build}"/>
        <delete dir="${dist}"/>
      </target>
    </project>
      

  3.   

    Ant可不仅仅是编译工具,它是构建工具,可以打包,备份,编译等等,只有你想不到,没有它不能干的.
    总之一个字:好的一塌糊涂.
      

  4.   

    看看他的doc就知道了~~
    里面有些具体的例子,看看就懂了
      

  5.   

    ant只是一个用java写的make工具,并不仅仅是编译,内置了很多task,也可以自己扩展task。
    我就是用它实现
    1。生成javadoc
    2。使用java2html生成再线源代码
    3。国际化
    4。编译
    5。打包
    6。发布
    7。备份
    我觉得这些就够了。
    也可以添加上:
    1。checkin/check out,
    2。junit测试,并将测试结果通过email发送
    3。可以操作数据库
    4。。
    等等。还是那句老话,只有你想不到,没有你作不到。
      

  6.   

    beyondii(十万个为什么) 
    你是怎么学会的,看资料还是书?
      

  7.   

    找一些资料看看。ant带的文档也很详细了。也可以去apache下载一些开源的java项目,基本上都是ant构建的,照抄就可以了。
    我的网站有一些资料。www.ibeyond.org
    如果用eclipse写ant的build.xml也是非常方便的,因为eclipse内置了对ant的支持。
      

  8.   

    抄抄ANT的例子就知道怎么用了
      

  9.   

    Another example. (A bit long, hope it will not greatly challenge your patience.) You see, it includes many targets, very powerful and useful.<?xml version="1.0"?>
    <project name="rdhservice" default="dist" basedir=".">
      
      <property name="name" value="dispatcher"/> <!-- service name -->
      <property name="src" value="src"/>
      <property name="work" value="work"/>
      <property name="build" value="build"/>
      <property name="dist" value="dist"/>
      <property name="lib" value="lib"/>
      <property name="bin" value="bin"/>
      <property name="api" value="docs/api"/>
      <property name="rdh" value="rdh"/>
      <property name="serverip" value="127.0.0.1"/> <!-- for deploy -->
      <property environment="env"/>
      <target name="prepare">
        <!-- create time stamp -->
        <tstamp/>
        <!-- create directory -->
        <mkdir dir="${build}"/>
        <mkdir dir="${dist}"/>
        <mkdir dir="${bin}"/>
        <mkdir dir="${api}"/>
        <mkdir dir="${work}"/>
      </target>  <target name="compile" depends="prepare">
        <javac srcdir="${src}" destdir="${build}" debug="on">
          <classpath>
            <fileset dir="lib"><include name="**/*.jar"/></fileset>
            <fileset dir="olib"><include name="**/*.jar"/></fileset>
          </classpath>
        </javac>
      </target>  <target name="dist" depends="compile">
        <jar jarfile="${lib}/uaproxy.jar">
          <fileset dir="${build}">
            <include name="rdh/uauth/**"/>
            <exclude name="rdh/uauth/rds/**"/>
          </fileset>
        </jar>
        
        <copy todir="${env.CATALINA_HOME}/webapps/axis/WEB-INF/lib">
          <fileset dir="${lib}"/>
        </copy>
      </target>  <target name="package" depends="compile">
        <zip zipfile="${dist}/${name}-${DSTAMP}.zip" basedir="." 
             excludes="${dist}/**,${build}/**,**/*.class,**/*.old,**/*.log,**/vssver.scc">
        </zip>
      </target>  <target name="doc" depends="prepare">
        <javadoc sourcepath="src" destdir="docs/api" 
                 author="true" version="true" use="true"
                 windowtitle="RDH User Authentication and Directory Service API" 
                 packagenames="jp.co.ricoh.rdh.*">
          <classpath>
            <fileset dir="lib"><include name="**/*.jar"/></fileset>
            <fileset dir="olib"><include name="**/*.jar"/></fileset>
          </classpath>
          
          <doctitle><![CDATA[<h1>RDH Service</h1>]]></doctitle>
          <bottom><![CDATA[<i>Copyright &#169; 2003 XXX Company, Ltd.
                  All Rights Reserved.</i>]]></bottom>
        </javadoc>
      </target><!-- generate easywsdl from source xml file -->
      <target name="easywsdl" depends="prepare">
        <!-- generate easywsdl -->
        <style in="spec/ua2/uauthenticationSource.xml"
           out="spec/ua2/uauthentication.xml" style="spec/ua2/uauthenticationMacro.xsl"/>
      </target><!-- create documents from spec xml files -->
      <target name="spec" depends="easywsdl">
        <!-- generate WSDL -->
        <style destdir="spec/ua2" basedir="spec/ua2" includes="*.xml" excludes="*Source.xml"
           extension=".wsdl" style="spec/ua2/easywsdl.xsl"/>
        <!-- generate HTML from WSDL (en) -->
        <style destdir="docs/ua2" basedir="spec/ua2" includes="*.xml" excludes="*Source.xml"
           extension=".en.html" style="spec/xmltospec-e.xsl"/>
      </target>  <taskdef name="wsdl2java" classname="org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask">
        <classpath>
          <fileset dir="lib"><include name="**/*.jar"/></fileset>
          <fileset dir="olib"><include name="**/*.jar"/></fileset>
        </classpath>
      </taskdef>  <target name="wsdl2java" depends="spec">
        <!-- for ua2 -->
        <wsdl2java url="spec/ua2/uauthentication.wsdl"
                   output="work"
                   deployscope="application"
                   serverSide="yes"
                   skeletonDeploy="yes"
                   noimports="no"
                   verbose="no"
                   testcase="no">
          <mapping namespace="http://xx.xx.xx/xmlns/soap/rdh/uauthentication-v2"
                   package="rdh.uauthentication_v2"/>
        </wsdl2java> 
      </target>  <target name="deployd" depends="compile" >    
    <java classname="org.apache.axis.client.AdminClient" fork="yes" classpathref="test.classpath" >
      <arg value="-lhttp://${serverip}:8080/axis/services/AdminService" /> 
      <arg value="olib/ua/deployd.wsdd" /> 
    </java>
      <target name="undeployd" depends="compile" >    
        <java classname="org.apache.axis.client.AdminClient" fork="yes" classpathref="test.classpath" >
      <arg value="-lhttp://${serverip}:8080/axis/services/AdminService" /> 
      <arg value="olib/ua/undeployd.wsdd" /> 
        </java>
      </target>  <path id="tcpmon.classpath">
        <pathelement location="olib/axis.jar" /> 
      </path>  <target name="tcpmon">
        <java classname="org.apache.axis.utils.tcpmon"  fork="yes" classpathref="tcpmon.classpath">
        <arg value="8081" /> 
      <!--  the listener port  --> 
        <arg value="localhost" /> 
      <!--  the target host  --> 
        <arg value="8080" /> 
      <!--  the target port  --> 
        </java>
      </target>
      
    </project>