下载解压到目录
d:\javatool\jar\
新建环境变量
变量名:ANT_HOME
变量值: d:\javatool\jar\apache-ant-1.7.1
变量名:path
变量值:%ANT_HOME%\bin
win+r 输入cmd
ant
出现 Buildfile:build.xml does not exist!
Build failed!
恭喜你,安装成功!
==不成功?什么?JDK没装?晕!
安装JDK
E:\Program Files\Java\
新建环境变量
变量名:JAVA_HOME
变量值:E:\Program Files\Java\jdk1.6.0_03
变量名:path
变量值:%ANT_HOME%\bin;%JAVA_HOME%\bin
变量名:CLASSPATH
变量值:E:\Program Files\Java\jdk1.6.0_03\lib\tools.jar
现在可以了吧,呵呵
前面不是说build.xml 不存在吗?我们写一个给他好了
新建项目(我用的是Eclipse)
new --> JavaProject
JavaTest
new --> class
HelloAnt.java
package com.tang.ant;
public class HelloAnt{
public static void main(String[] args){
System.out.println("Hello world!I am an ant!");
}
}
new --->xml
build.xml
<?xml version="1.0" encoding="UTF-8"> <project name="helloAnt" default="rerun" basedir="."> <property="src" value="src"/> <property="dest" value="dest"/> <property="lib" value="lib"/> <property="hello_jar" value="hello1.jar"/> <target name="init"> <mkdir="${dest}"> </target> <target name="compile" depends="init"> <javac srcdir="${src}" destdir="${dest}"/> </target> <target name="build" depends="compile"> <mkdir="${lib}"/> <jar jarfile="${lib}/${hello_jar}" basedir="${dest}"> <manifest> <attribute name="Main-Class" value="com.tang.ant.HelloAnt"/> </manifest> </jar> </target> <target name="run" depends="build"> <java classname="com.tang.ant.HelloAnt" classpath="${lib}/${hello_jar}"/> </target> <target name="clean" depends="run"> <delete dir="${dest}"/> </target> <target name="rerun"> <ant target="run"/> </target> </project>
cmd
d:\workspace\JavaTest>ant
当出现
build successful
成功了
d:\workspace\JavaTest\lib 目录下会有一个hello1.jar包
cmd
d:\workspace\JavaTest\lib> java -jar hello1.jar