Setting JAVA_HOME and ANT_HOME in RHEL

How do you get a newer version of Ant to work on on RedHat?

Simply setting ANT_HOME and JAVA_HOME aren’t enough!

Need to add alternatives for applications in RHEL.

set java

sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_101_x86_64/bin/java

set javac

sudo alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_101_x86_64/bin/javac

set ant

sudo alternatives --install /usr/bin/ant ant /opt/apache-ant-1.9.7_x86_64/bin/ant

And lastly... rename or modify /etc/ant.conf because by default the ant.conf file is sourced by ant scripts which automatically re-exports ANT_HOME using an older version of ANT.

You can tell this is the case when, for example:

bash-4.1$ ant -version

Apache Ant version 1.7.1 compiled on July 2 2010

And 

bash-4.1$ ant --noconfig -version

Apache Ant(TM) version 1.9.7 compiled on April 9 2016

Now your JAVA_HOME, java -version should match and your ANT_HOME and ant -version should match!

If this doesn't report back the version you expected, confirm they are set as priority in the alternatives:

sudo alternatives --config java

sudo alternatives --config javac

sudo alternatives --config ant