Installing Ant - rajivkanaujia/alphaworks GitHub Wiki
Install Ant using Homebrew
Run following command on Terminal
$ brew update
$ brew install ant
The response will be similar to one below. Note the location of "ant",
==> Installing dependencies for ant: openjdk
==> Installing ant dependency: openjdk
==> Downloading https://homebrew.bintray.com/bottles/openjdk-13.0.2+8_2.catalina.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/65/65adca036393f528e3830cab8b0aafec94be870de087d94cfe098fd5935
######################################################################## 100.0%
==> Pouring openjdk-13.0.2+8_2.catalina.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because it shadows the macOS `java` wrapper.
If you need to have openjdk first in your PATH run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.bash_profile
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
==> Summary
🍺 /usr/local/Cellar/openjdk/13.0.2+8_2: 631 files, 314.6MB
==> Installing ant
==> Downloading https://www.apache.org/dyn/closer.lua?path=ant/binaries/apache-ant-1.10.7-bin.tar.xz
==> Downloading from https://downloads.apache.org/ant/binaries/apache-ant-1.10.7-bin.tar.xz
######################################################################## 100.0%
==> Downloading https://www.apache.org/dyn/closer.lua?path=ant/ivy/2.4.0/apache-ivy-2.4.0-bin.tar.gz
==> Downloading from http://apache.mirrors.hoobly.com/ant/ivy/2.4.0/apache-ivy-2.4.0-bin.tar.gz
######################################################################## 100.0%
==> Downloading https://www.apache.org/dyn/closer.lua?path=commons/bcel/binaries/bcel-6.4.0-bin.tar.gz
==> Downloading from https://mirrors.gigenet.com/apache/commons/bcel/binaries/bcel-6.4.0-bin.tar.gz
#=#=#
curl: (22) The requested URL returned error: 404
Trying a mirror...
==> Downloading https://archive.apache.org/dist/commons/bcel/binaries/bcel-6.4.0-bin.tar.gz
######################################################################## 100.0%
🍺 /usr/local/Cellar/ant/1.10.7_1: 1,670 files, 41.9MB, built in 33 seconds
==> Caveats
==> openjdk
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because it shadows the macOS `java` wrapper.
If you need to have openjdk first in your PATH run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.bash_profile
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
Check location of ant
$ which ant
/usr/local/bin/ant
Check the version using ant
$ ant -version
Apache Ant(TM) version 1.10.7 compiled on September 1 2019
Configure .bash_profile
export ANT_HOME=/usr/local/Cellar/ant/1.10.7_1
export PATH=${PATH}:${ANT_HOME}/bin
Add following in your .bash_profile to check for the ANT_HOME folder to exist. Error could also mean that you have upgraded and not update your .bash_profile
[ -d $ANT_HOME ] && echo " Directory $ANT_HOME exists." || echo " Error: Directory $ANT_HOME does not exists."
Handling errors
Error at -version command
$ ant -version
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
Run command like
$ ant --execdebug
exec "$JAVACMD" -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH" "-lib" "/usr/local/share/ant"
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
Try to use command like one mentioned below to see how the variables resolve.
$ echo exec "$JAVACMD" -classpath "$LOCALCLASSPATH" -Dant.home="$ANT_HOME" -Dant.library.dir="$ANT_LIB" org.apache.tools.ant.launch.Launcher -cp "$CLASSPATH" "-lib" "/usr/local/share/ant"
You will find some of the variables are not getting resolved. So add them in the .bash_profile
export JAVACMD=${JAVA_HOME}/bin/java
export LOCALCLASSPATH=${ANT_HOME}/libexec/lib/ant-launcher.jar
export ANT_LIB=org.apache.tools.ant.launch.Launcher
Note: If you like the instructions here, please refer it on your posts/documentation. Contact me if there are corrections needed.