在Ant中引用外部的任务

来源:互联网 发布:网络兼容模式怎么设置 编辑:程序博客网 时间:2024/05/02 03:02
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

Ant为使用者提供了大量的任务,更为可贵的是,它允许使用者使用其它开发者开发的任务。在Ant主页上就有一个外部任务列表:Ant.apache.org/external.html">http://Ant.apache.org/external.html。只要你愿意,你也可以很快写出一个自己的任务来,看看本系列的“编写自定义任务,轻松扩展Ant”就行了。

<>Ant中引外部任务有两种情况: 

一、Ant定义的可选任务

这些任务可以说是半官方的任务了,任务实际上已经写好了,不过该任务依赖的资源主要就是jar文件没有跟Ant一起发布。例如FTP任务就是这种情况。打开文档<Ant install dir>docsmanualinstall.html#librarydependencies,原来还要到jakarta.apache.org下载1.1.0或更高版本的commons-net 2.0.8或更高版本的jakarta-oro。注意这是针对Ant1.6说的,不同的Ant版本使用的外部库可能不一样。把下载到的commons-net-1.1.0.jar放到<Ant install dir>lib目录下,OK,你现在就可以使用FTP了:

<><ftp server="ftp.apache.org"           remotedir="incoming"              userid="anonymous"               password="me@myorg.com"         depends="yes"  >                <fileset dir="htdocs/manual"/>  </ftp> <> 二、一般的外部任务

这些任务同样需要下载所需的jar文件,放到<Ant install dir>lib目录下,同时在build.xml中需要定义这些外部任务。在Ant.apache.org/external.html%E4%B8%8A%E6%9C%89%E4%B8%80%E4%B8%AATimer">http://Ant.apache.org/external.html上有一个Timer任务,在下载jar后我们可以这样引用

build.xml:

<?xml version="1.0" ?>

<project name="testTimer" default="test">

       <taskdef name="timer" classname="de.jeckle.AntExtension.Timer"/>

<>        <target name="test">

              <timer verbose="true">

                     <echo>test1</echo>

              </timer>

              <timer name="timer2">

                     <echo>test2</echo>

                     <timer name="timer3" verbose="true">

                            <echo>test3</echo>

                     </timer>

                     <echo>test4</echo>

              </timer>

       </target>

  <></project>

 

最后说说设置类路径的几种办法:

1.Ant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">  jar文件放到Ant安装目录的lib目录下,Ant会自动装载

2.Ant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">  设置环境变量CLASSPATH,包含要引用的jar文件

3.Ant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;">  TaskDef中指定classpath

<taskdef name="timer" classname="de.jeckle.AntExtension.Timer" classpath=”../lib/timer.jar”/>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>