Ant Getting Started-configuring and using

Source: Internet
Author: User
Tags contains copy include mkdir variables

modifying properties in Environment variables

Increase the------c:\ant\bin before the Path property, so you can use ant

The Build.xml file contains one project and at least one target element, and the target element contains one or more task elements, and the task is an executable code.

The root element is project, three properties Name,default,basedir

Name Specifies the project names

default Specifies the target element for the project

BASEDIR Specifies the base path for the project, if it is ".", which is represented as the path of the Build.xml

<project name= "Bookstore" default= "about" basedir= "." >

<target name= "Init" > <tstamp/>

<!--initialize the names of each variable--> <property name= "Build" value= "builds"/><!--compiled directory--> <property " src "value=" src "/><!--the location of the source files-->

<!--the package--> of the environment variables used

<property environment= "myenv"/> <property name= "Servletpath" value=. Catalina_home}/common/lib/servlet-api.jar "/> <property name= mysqlpath" value= "WEB-INF/lib/mysqldriver.jar" />

<mkdir dir= "${build}"/><!--call the previous directory parameter is ${xxx}--> <mkdir dir= "${build}\web-inf"/> <mkdir "dir=" ${ Build}\web-inf\classes "/>

<copy todir= "${build}" ><!--copy directory files to the new directory--> <fileset dir= "${basedir}" ><!--the original directory is a basedir parameter --> <include name= "*.jsp"/> <include name= "*.bmp"/> <include name= "WEB   -inf/** "/> <exclude name= build.xml"/><!--do not copy this file--> </fileset> </copy> </target>

<target name= "Compile" depends= "init" > <!--it relies on the execution of Init, so calling it executes first init-->

<javac srcdir= "${src}" destdir= ${build}/web-inf/classes "classpath=" ${servletpath}:${mysqlpath } "> </javac> </target>

<target name= "Bookstorewar" depends= "compile" > <!--the task of generating the war-->

<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" > <!--default target--> <echo> This build.xml file contains targets fo R Building Bookstore Web application </echo> </target>


We have this build.xml in the root of our application

So the way to run Ant is: Under DOS

1. Enter C:\MYAPP, our application directory input: Ant (will search the current path of the Build.xml file)

2. Direct Input Ant-buildfile C:\myApp\build.xml

3. Direct input Ant-buildfile c:\myApp\build.xml about

All three of these methods execute the target of about, and if you want to compile the Java file, we just

Ant-buildfile C:\myApp\build.xml Compile

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: 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.