初识ant

初识ant

Ant的简介:类似make工具,但可以支持多平台
Ant的安装:配置ant的准备工作:ant_home 指Ant的安装目录,在path中加入%ant_home%/bin,用于命令行下
        运 行ant
Ant的结构:主要是通过对build.xml的配置,
                     Ant内置任务:                                                描述
                        property                                              设置name/value的属性        
                        mkdir                                                   创建目录
                        copy                                                     拷贝
                        delete                                                   删除
                        javac                                                    编绎
                        war                                                      打包
下面是一个简单build.xml的示例:
<project name="bookstore" default="about" basedir=".">

    <target name="init">
        <tstamp/>
        <property name="build" value="build" />
        <property name="src" value="src" />
        <property environment="myenv" />
        <property name="servletpath"  value="${myenv.CATALINA_HOME}/common/lib/servlet-api.jar" />
        <property name="mysqlpath" value="WEB-INF/lib/mysqldriver.jar" />

 <mkdir dir="${build}" />
 <mkdir dir="${build}\WEB-INF" />
 <mkdir dir="${build}\WEB-INF\classes" />

      <copy todir="${build}" >
        <fileset dir="${basedir}"    >
           <include name="*.jsp" />
           <include name="*.bmp" />
           <include name="WEB-INF/**" />
           <exclude name="build.xml" />
        </fileset>
     </copy>
 
   </target>


  <target name="compile" depends="init">       

     <javac srcdir="${src}"
             destdir="${build}/WEB-INF/classes"
             classpath="${servletpath}:${mysqlpath}">
     </javac>
  </target>
 
   <target name="bookstorewar" depends="compile">       

    <war warfile="${build}/bookstore.war" webxml="${build}/WEB-INF/web.xml">
 <lib dir="${build}/WEB-INF/lib"/>
 <classes dir="${build}/WEB-INF/classes"/>
 <fileset dir="${build}"/>
    </war>
    </target>

  <target name="about" >
        <echo>
 This build.xml file contains targets
       for building bookstore web application
        </echo> 
   </target>

</project>

从示例我们看出来,整个xml是一个project,project下有几个为init,compile,的target
运行时首先在这个目录下打开dos窗口,以这个xml为准,如果你只运行ant那么只会输出echo中的内容
因为project的default是about; 如果运行ant complie 它会执行两个target: init 和complie,因为complie是依靠init
的。
      用了以后发现ant 原来很简单,当然现在只是学了个皮毛而已。

你可能感兴趣的:(初识ant)