
开始安装
目前官网提供的下载版本为1.9.x 1.10.x,ant的安装方式跟jdk的离线安装类似

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

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



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


ant安装依赖jdk(java.exe)、依赖lib及path的配置;
正确配置是命令路径可被找到

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>
<!-- set global properties for this build -->
<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">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source">
<!-- Compile the Java code from ${src} into ${build} -->
<!--1. 通过变量设置 -->
<!--<javac srcdir="${src}" destdir="${build}" classpath="${classpath3d}"/>-->
<javac srcdir="${src}" destdir="${build}">
<!--2. 通过引用设置 -->
<!--<classpath refid="classpath3d"/>-->
<!--3. 直接写明 -->
<!--<classpath path="lib/mysql-connector-java-8.0.29.jar"/>
<classpath path="lib/ojdbc8.jar"/>-->
<!-- 4. 聚合 -->
<!--<classpath>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</classpath>-->
</javac>
</target>
<target name="dist" depends="compile"
description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<copy todir="${dist}/lib">
<fileset dir="lib" erroronmissingdir=""/>
</copy>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<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编译完成目录结构示例:
