---
title: "Ant基础"
author: "iammonster"
date: "2008-12-01T18:36:09Z"
tags: []
slug: "ant"
draft: false
lastmod: "2008-12-02T18:41:47Z"
id: 284256
url: "https://jiajun.iteye.com/blog/284256"
---

前面一篇文章，算是Ant入门，下面以实例说明一些应用：

 

1、property：

     变量的用处我就不用说了，特别是配置里面有个变量那实在是爽！

```
<!-- ================================= 
	        用property定义一些变量 ,其实就是一些名值对
           如：定义变量src指向src目录，下面应用的时候就可以用${src}
                定义变量target_classes指向anttest/bin/WEB-INF/classes目录
 ================================= -->
<property name="src" location="src"></property>
<property name = "target_classes" location = "bin/WEB-INF/classes" />
```

 

```
<!-- ================================= 
		         但是当你把文件列表作为一个变量后就不容易维护，可以通过下面的方法来做到：   
		         ================================= -->
	<path id="lib_jar">
		<fileset dir="${lib.dir}">
	    	<include name="**/*.jar"/>
		</fileset>
	</path>
```

 

 

2、建立一个任务，如：

```
<!-- ================================= 
          target: copytest  
          把当前工程的bin/anttest下面的特定文件拷贝到copytest
          拷贝的文件包括后缀为js的文件，除去后缀为jsp的文件              
         ================================= -->
    <target name="copytest"  description="拷贝文件">
        <copy todir="copytest">
        	<fileset dir="bin/anttest">
			    <include name="*.js"/>
			    <exclude name="*.jsp"/>
			</fileset>
        </copy>
    </target>
```

 3、