An omnipotent "ant."

Source: Internet
Author: User
Tags comments
Five . Use Ant running local Programs

1. use ant to run Windows in a batch file to run an external program within ant, use the <exec> Task. It allows you to do the following: L Specify the program name and the parameters to be passed in. L NAME the running directory. L Use the FAILONERROR flag to control whether the build stops when the application fails. L Specify a maximum program duration, over which the program aborts. A task is considered a failure at this time, but at least the build aborts, rather than hangs, which is essential for automatic construction. L Save the output to a file or attribute. l Specifies the environment variables that need to be preset when Java invokes the local program.

Here's an example: Batch file: Test.bat

@echo off

echo Hello > Test.txt


Posted in @ November 16, 2005 14:44:00 | Comments (6)
The omnipotent "Ant"--ant (iii)

Four.UseAnttoJunitTestIn addition to using Java to run JUnit directly, we can also use the JUnit task provided by JUnit to run with Ant.         Several major ant tasks involved are as follows: l &LT;JUNIT&GT;, define a junit task L <batchtest>, in <junit>, run multiple testcase l <test&gt, in <junit>, running a single testcase L &LT;FORMATTER&GT, in <junit>, defining a test result output format L <ju Nitreport>, define a junitreport task L <report>, located in <junitreport>, output a junit to run JUnit needs Jakart A-ant-1.4-optional.jar and Junit.jar packages, because they are used to support ant task--<junit>, so they cannot be loaded in Build.xml files and need to be placed in Ant_ Home. Use eclipse to follow the steps to add: Windows-preference-ant-runtime-ant home Entries Look at the example of a JUnit test:

<?xml version= "1.0"?>

<project name= "project" default= "JUnit" >

<property name= "Run.classpath" value= "Bin" ></property>

<property name= "Run.srcpath" value= "src" ></property>

<property name= "Test.srcpath" value= "test" ></property>

<property name= "Lib.dir" value= "Lib"/>

<path id= "Compile.path" >

<pathelement location= "${lib.dir}/junit-3.8.1.jar"/>

<pathelement location= "${lib.dir}/log4j-1.2.8.jar"/>

</path>

<target name= "Compile" >

<javac destdir= "${run.classpath}" srcdir= "${run.srcpath}"

classpathref= "Compile.path"/>

<javac destdir= "${run.classpath}" srcdir= "${test.srcpath}"

classpathref= "Compile.path"/>

</target>

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

<junit printsummary= "true" >

<classpath path= "${run.classpath}" ></classpath>

<test name= "Org.ant.test.Test1" ></test>

</junit>

</target>

</project>


Posted in @ November 16, 2005 14:29:00 | Comments (0)
November 09, 2005 Ant profile

a . Ant Introduction : ant----Another Neat Tool, is a java-based cross-platform build tool, as an excellent build tool Ant has the following advantages: Ø simple syntax, easy to learn , if you have used XML, you will feel this more; Ø easy to use, reduce the number of makefile written in large software projects based on Make method; Ø Manage Java classpath and file directory structure in a smart way across platforms; Ø run fast, all Java can be launched in Ant's JVM; Ø tightly integrated with the JUnit test framework to achieve extreme programming unit testing; Ø it can be easily extended with the Java language; Ø built-in support for the development of Java EE, such as EJB compilation and packaging, etc.; Ø to solve the deployment problems of Java projects: such as ftp,telnet, Application Server, SQL commands, etc., these can be automatically deployed.

Ant's official website: The latest version of Http://ant.apache.org/Ant: Ant 1.6.5 All examples of this article run the environment: jdk1.4.2,ant1.6.2,eclipse3.0

two . introduce Ant of the DATATYPE        and Characteristics Ant's core task is target, an ant file has multiple target components, and there is a dependency--depends between these target, which runs by default and runs the target specified in project. When building a typical Java project, Most of the steps are used to process files and paths (such as classpath), and Ant-provided datatype can naturally handle both concepts. File sets and paths, and several other types of datatype, form the basic structure of Ant's Build files.

1 . Paths (path) What we often use in Javac is Classpath, an example of a path definition is as follows:

<classpath>

<pathelement location = "Lib/some.jar"/>

</classpath> location allows you to specify a single file or directory, or you can extend the current path through another path, using path instead of location:

<classpath>

<pathelement Path = "Build/classes;lib/some.jar"/>

</classpath> the delimiter between elements in a path definition can be separated by semicolons, colons, and the path delimiter using a slash, a backslash, and no need to consider operating system differences.

2. File Set (fileset) all the build processes implicitly operate on a series of files, and Ant looks at the set of files as a local datatype, and here's an example This example is to copy files from one directory to another:

<copy todir= "New_web" >

<fileset dir= "Web"/>

</copy> we usually need to include or exclude some files during the build process, and here are some examples of typical file sets:

<fileset>

<include name= "**/*test.java"/>

</fileset>

<fileset>

<exclude name= "**/*.jsp"/>

</fileset> By default, the values in include and exclude are case sensitive and can be canceled by setting casesensitive= "false". In many cases, the IDE and the Code management system generate a lot of temporary files, we have to set the exclusion clause in each file set, in order to avoid this situation, Ant's exclusion mode for these special patterns is activated by default (for example: **/cvs,**/#* #等), Detailed mode to find the relevant documents!.

3. Mode set (patternset)        Use one of Ant's other core datatype: pattern sets in a file set to implement inclusion and exclusion functions. Pattern matching functions are as follows: l       *   refers to characters from zero to any length. l      ?  refers to a single character. l       * * is the directory name that represents all of the directories on the directory tree that are down from the current power saving, and can be 0 to any number of directories. The l      ///End mode means the end is * *.       

4. selector (Selector) Ant1.5 The above version contains a sophisticated new feature, selector, which he uses to select the text contained in the file set The introduction of several commonly used built-in selectors: <filename>: Based on pattern matching files, working in a manner similar to the include or exclude elements of a pattern set <size>: Select a file with a condition of less than, greater than, or equal to the specified value. <DATE>: Select the file at the last modified time, later than or equal to the specified value. <PRESENT>: Select a file that exists in another directory tree.        <contains> Select the file that contains the specified string. These selectors can be merged into the selector container to provide a grouping and logical representation, which is the <and>,<or>,<not>,<none> and <majority> comparison of two directories. and copy files that exist only in one directory to another directory, we use <not> and <present>

<copy todir= "Newfiles" >

<fileset dir= "Web" >

<not>

<present targetdir= "Currebtfiles"/>

</not>

</fileset>

</copy> using the <contains> selector, we can select files that contain only specific strings:

<copy todir= "Newfiles" >

<fileset dir= "Web" >

<contains text= "System"/>

</fileset> </copy>.

Here's a quick look at Ant's Feature: property, which is conceptually similar to Java.util.Property, which allows you to customize attributes in a build file and allow environment variables as attributes. The property has special permissions that he can perform outside of <target>, with specific usage, which will be illustrated with examples below.

   &nbs

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.