ant学习

来源:互联网 发布:网络转换器是什么 编辑:程序博客网 时间:2024/05/17 06:15

1.ant简介 略:

2.一些问题:

eclipse自动生成build.xml:右建项目->export->general->ant buildfiles。可在项目下看到build.xmls

3.代码如下 这里项目名为test3, 内无代码

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. --><project basedir="." default="build" name="test3">
    <property environment="env"/>

#prorerty可以看做是定义变量后面可以用${name}[=后面的value]引用
    <property name="ECLIPSE_HOME" value="../../eclipse-kepler"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.7"/>
    <property name="source" value="1.7"/>

    <path id="test3.classpath">
        <pathelement location="bin"/>
    </path>

#看ant xml文件大框架看target,每个target相当于一个操作
    <target name="init">
        <mkdir dir="bin"/>

#copy todir 复制目标文件,fileset dir 复制源文件   exclude  排除的 不需要复制的文件
        <copy includeemptydirs="false" todir="bin">
            <fileset dir="src">
                <exclude name="**/*.launch"/>
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>

#删除dir 目录
    <target name="clean">
        <delete dir="bin"/>
    </target>

#target 如果有depends  就是先执行clean target再执行本target  相当于定以了一个顺序关系
    <target depends="clean" name="cleanall"/>
    <target depends="build-subprojects,build-project" name="build"/>
    <target name="build-subprojects"/>
    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
            <src path="src"/>
            <classpath refid="test3.classpath"/>
        </javac>
    </target>
    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
    <target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
        <copy todir="${ant.library.dir}">
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </copy>
        <unzip dest="${ant.library.dir}">
            <patternset includes="jdtCompilerAdapter.jar"/>
            <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
        </unzip>
    </target>
    <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target>
</project>


4.有时候会看到如下代码    

<taskdef resource="net/sf/antcontrib/antlib.xml">
        <classpath>
            <pathelement location="lib/ant-contrib.jar"/>
        </classpath>
    </taskdef>

taskdef 相当于第三方任务,resource使用安装ant-contrib.jar包

详细参看http://blog.163.com/yang_jianli/blog/static/161990006201272455531446/

0 0
原创粉丝点击