下载地址:https://downloads.apache.org/ant/binaries/
JDK: 1.8
官网: https://ant.apache.org/manual/index.html
ANT依赖jdk,所以需要提前配置好JDK
目前官网提供的下载版本为1.9.x 1.10.x,ant的安装方式跟jdk的离线安装类似

解压下载的ant包到安装位置

https://ant.apache.org/manual/install.html#installing
ant的安装过程为配置ant命令可执行的过程
需要配置环境变量ANT_HOME 、CLASSPATH
以下摘自官网
ANT_HOME : ant 安装目录

CLASSPATH: ant lib目录所在目录
(注意不要覆盖JAVA lib/tools\rt的设置)
classpath的目录官方的安装文档中标注需要,但实际测试中可能并不需要,尽管如此依然建议进行配置,Linux环境下跳过

ant -version

#默认使用build.xml
ant
#使用非默认build.xml 文件通过-f指定
ant -f mybuild.xml
增加classpath的设置说明(四种方式)
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
description>
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<path id="classpath3d">
<fileset dir="lib" erroronmissingdir="false">
<include name="*.jar"/>
fileset>
path>
<property name="classpath3d" refid="classpath3d"/>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
target>
<target name="compile" depends="init"
description="compile the source">
<javac srcdir="${src}" destdir="${build}">
javac>
target>
<target name="dist" depends="compile"
description="generate the distribution">
<mkdir dir="${dist}/lib"/>
<copy todir="${dist}/lib">
<fileset dir="lib" erroronmissingdir=""/>
copy>
<jar jarfile="${dist}/MyProject-${DSTAMP}.jar" basedir="${build}"/>
target>
<target name="clean"
description="clean up">
<delete dir="${build}"/>
<delete dir="${dist}"/>
target>
project>
src下编写java代码
示例
//src/A.java
public class A{
private String var1;
private String demo(String args){
System.out.println(args);
return "OK";
}
}
目录结构示例

ant
编译完成目录结构示例:

https://ant.apache.org/manual/using.html#buildfile
完整源码: https://gitcode.net/master336/ant-demo