Reference external tasks in ant

Source: Internet
Author: User

Ant provides users with a large number of tasks. More importantly, it allows users to use tasks developed by other developers. There is an external task list on the ant homepage: http://ant.apache.org/external.html. As long as you want, you can quickly write a task of your own to see the series of "Writing custom tasks and easily expanding ant.

There are two cases of referencing external tasks in ant:

 

1. Optional tasks defined by ant

These tasks can be said to be a half-official task. The task has actually been written, but the resource that the task depends on is mainly because the JAR file is not released with ant. For example, this is the case for FTP tasks. Open the <ant install dir>/docs/manual/install.html # librarydependencies document. You have to download commons-net of version 1.1.0 or later and Jakarta-Oro of version 2.0.8 or later from jakarta.apache.org. Note that this is for ant1.6. Different ant versions may use different external libraries. Put the downloaded commons-net-1.1.0.jar in the <ant install dir>/lib directory, OK, you can use FTP now:

<FTP Server = "ftp.apache.org"

Remotedir = "Incoming"

Userid = "anonymous"

Password = "me@myorg.com"

Depends = "yes"

>

<Fileset dir = "htdocs/manual"/>

</Ftp>

 

2. General external tasks

These tasks also need to download the required jar files, put them in the <ant install dir>/lib directory, and define these external tasks in build. xml. There is a timertask on http://ant.apache.org/external.html. after jars are downloaded, We can reference this example.

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>

 

Finally, let's talk about several ways to set the class path:

1. Put the JAR file in the lib directory of the ant installation directory, and ant will automatically load

2. Set the environment variable classpath, including the JAR file to be referenced

3. Specify classpath in taskdef

<Taskdef name = "timer" classname = "De. Jeckle. antextension. Timer" classpath = "../lib/Timer. Jar"/>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.