Ant简单工程的构建
1.在Ant的官方网站http://ant.apache.org/bindownload.cgi下载Ant最新版本(我下载的是apache-ant-1.8.2-bin.zip),Ant无需安装,直接解压后设置环境变量即可。
2.测试Ant是否安装成功,在控制台运行ant命令,出现如下提示则成功:
3.创建一个HelloWorld工程,创建一个HelloWorld.java和build.xml,如下:
package com.helloworld; public class HelloWorld { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Hello World"); } }
<?xml version="1.0" encoding="UTF-8"?> <project name="HelloWorld" default="run" basedir="."> <property name="src" value="src"/> <property name="dest" value="build/classes" /> <property name="lib" value="build/lib" /> <property name="hello_jar" value="build/lib/hello.jar" /> <target name="init"> <mkdir dir="${dest}" /> <mkdir dir="${lib}" /> </target> <target name="complie" depends="init"> <javac srcdir="${src}" destdir="${dest}" /> </target> <target name="build" depends="complie"> <jar destfile="${hello_jar}" basedir="${dest}" > <manifest> <attribute name="Main-Class" value="HelloWorld" /> </manifest> </jar> </target> <target name="run" depends="build"> <java classname="com.helloworld.HelloWorld" classpath="${hello_jar}" /> </target> <target name="clean"> <delete file="${hello_jar}" /> <delete dir="${dest}" /> <delete dir="${lib}" /> </target> </project>
3.Ant构建工程
另:控制台构建