ant的使用

来源:互联网 发布:windows搭建私有云 编辑:程序博客网 时间:2024/05/20 23:59

在介绍ant使用之前,给大家推荐两个学习ant的链接:

ant基础任务API

ant扩展任务API


大家在网上能很容易搜到的知识点,我在这里就不罗嗦了!下面介绍一下我在开发中遇到的小问题,算是细节吧!

1、执行ant 构建文件命令的区别(具体执行过程大家可以开debug看一下 :  ant -debug -find 文件名.xml)

      1、ant 命令: 默认情况下,在当前目录下查找名为build.xml的构建文件并执行

      2、这三个命令 在当前目录下查找指定的构建文件,如果找不到,则报错

       ant -buildfile 文件名.xml

       ant -file 文件名.xml

       ant -f 文件名.xml

     3、这两个命令  在当前目录下查找指定的构建文件,如果找不到,就会到当前目录的上级目录下查找,在找不到的话,会到当前目录的上上级目录下查找,如果到系统的根目录下还没找到,则报错!

       ant -find 文件名.xml

       ant -s  文件名.xml

下面是我做的测试:
    G:\hrlu_tools\testAnt1.xml文件 

    <project name="anttest" default="test" basedir=".">      <target name="test">          <echo message="${basedir}"/>          <ant antfile="G:\hrlu_tools\udphr\testAnt2.xml"  useNativeBasedir="true"/>      </target>      </project>  

    G:\hrlu_tools\udphr\testAnt2.xml文件 

    <project name="anttest" default="test" basedir=".">      <target name="test">          <echo message="${basedir}"/>          <ant antfile="G:\hrlu_tools\udphr\testAnt2.xml"  useNativeBasedir="true"/>      </target>      </project>  

首先在cmd中 进入G:\hrlu_tools\udphr\  这个目录下,执行ant -find antTest1.xml,执行结果如下:

G:\hrlu_tools\udphr>ant -find testAnt1.xml
Searching for testAnt1.xml ...
Buildfile: G:\hrlu_tools\testAnt1.xml

test:
[echo] G:\hrlu_tools

test:
[echo] G:\hrlu_tools\udphr

BUILD SUCCESSFUL
Total time: 0 seconds

但是,如果你执行ant -f antTest1.xml,执行结果如下:

G:\hrlu_tools\udphr>ant -f testAnt1.xml
Buildfile: testAnt1.xml does not exist!
Build failed


看到区别了吧!!!


2、给大家说一下<project name="anttest" default="test" basedir=".">这个里面的basedir属性

属性 :basedir的作用

       用于指定基路径的位置。该属性没有指定时,使用 Ant 的构件文件的当前目录作为基准目录,


      当给basedir指定目录时,会将指定的值赋给basedir,下面是ant 开启debug的执行过程

G:\hrlu_tools\udphr>ant -debug -find testAnt1.xmlApache Ant(TM) version 1.9.6 compiled on June 29 2015Searching for testAnt1.xml ...Searching in G:\hrlu_toolsBuildfile: G:\hrlu_tools\testAnt1.xmlAdding reference: ant.PropertyHelperDetected Java version: 1.8 in: D:\tools\Java\jdk1.8.0_25\jreDetected OS: Windows 7Adding reference: ant.ComponentHelperSetting ro project property: ant.file -> G:\hrlu_tools\testAnt1.xmlSetting ro project property: ant.file.type -> fileAdding reference: ant.projectHelperAdding reference: ant.parsing.contextAdding reference: ant.targetsparsing buildfile G:\hrlu_tools\testAnt1.xml with URI = file:/G:/hrlu_tools/testAnt1.xmlSetting ro project property: ant.project.name -> anttestAdding reference: anttestSetting ro project property: ant.project.default-target -> testSetting ro project property: ant.file.anttest -> G:\hrlu_tools\testAnt1.xmlSetting ro project property: ant.file.type.anttest -> file<strong><span style="font-size:24px;">Project base dir set to: G:\hrlu_tools</span></strong>

       1、当在一个构建文件中使用<ant>调用其他构建文件时,如何保留其他构建文件中的basedir呢?如下:


    <ant antfile="G:\hrlu_tools\udphr\testAnt2.xml"  useNativeBasedir="true"/>  

          可以选择使用属性:useNativeBasedir值为ture时,保留子构建文件的basedir的值,值为false时 直接引用父构建文件中的值



后续会持续更新.......      

     


0 0
原创粉丝点击