AMP AMP

How to install Apache Ant in CentOS 7

To install Apache Ant in CentOS 7

Apache Ant is a Java library and command-line tool that help building software. Ant supplies a number of built-in tasks that allows to compile, assemble, and run Java applications. Its build files are written in XML so it is open standard, portable and easy to understand. users can also develop " antlibs" that will contain default Ant tasks and types to make readymade ant dependent library files. This tutorial explains the installation procedure of Apache Ant on CentOS 7.

Installation and Configuration procedure

To proceed with the installation procedure, check whether the target system is installed with Java Development Kit, because Apache Ant will use JDK during its build process. For this tutorial, the system has already been installed with JDK and to check the version of the Java that is installed, run the following command.

[root@linuxhelp ~]# java -version
java version " 1.8.0_121" 
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

After the JDK is installed and version has been checked, go ahead and install Apache Ant using its binary distribution from the official Apache web site. Execute the wget command followed by the download link.

[root@linuxhelp ~]# wget redrockdigimark.com/apachemirror//ant/binaries/apache-ant-1.10.1-bin.zip
--2017-09-22 17:36:05--  http://redrockdigimark.com/apachemirror//ant/binaries/apache-ant-1.10.1-bin.zip
Resolving redrockdigimark.com (redrockdigimark.com)... 119.18.61.94
Connecting to redrockdigimark.com (redrockdigimark.com)|119.18.61.94|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8824128 (8.4M) [application/zip]
Saving to: ‘ apache-ant-1.10.1-bin.zip’ 

100%[========================================================> ] 8,824,128   39.8MB/s   in 0.2s   
2017-09-22 17:36:24 (39.8 MB/s) - ‘ apache-ant-1.10.1-bin.zip’  saved [8824128/8824128]

The package has been downloaded and now extract it using unzip command as follows.

[root@linuxhelp ~]# unzip apache-ant-1.10.1-bin.zip
Archive:  apache-ant-1.10.1-bin.zip
   creating: apache-ant-1.10.1/
   creating: apache-ant-1.10.1/bin/
  inflating: apache-ant-1.10.1/bin/ant  
  inflating: apache-ant-1.10.1/bin/antRun
.
.
inflating: apache-ant-1.10.1/manual/usinglist.html  
 inflating: apache-ant-1.10.1/patch.xml  

Move the extracted contents to /opt/ directory.

[root@linuxhelp ~]# mv apache-ant-1.10.1/ /opt/ant

Make a symlink to ant/bin folder as shown below.

[root@linuxhelp ~]# ln -s /opt/ant/bin/ant /usr/bin/ant

Setup ANT Environment Variable

Create a file called ant.sh under /etc/profile.d/ directory. Add the following contents and save the file.

[root@linuxhelp ~]# vim /etc/profile.d/ant.sh
#!/bin/bash
ANT_HOME=/opt/ant
PATH=$ANT_HOME/bin:$PATH
export PATH ANT_HOME
export CLASSPATH=.

Make it executable by executing the following command.

[root@linuxhelp ~]# chmod +x /etc/profile.d/ant.sh

Then, set the environment variables permanently by running the following command.

[root@linuxhelp ~]# source /etc/profile.d/ant.sh

The environment variable are set. For the changes to make effect, log out or reboot your system. After the system comes back online, check the ANT version by executing the following command.

[root@linuxhelp ~]# ant &ndash version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017

Check the path and environment variables present by running either of the commands.

[root@linuxhelp ~]# echo $ANT_HOME
/opt/ant

Or

[root@linuxhelp ~]# echo $PATH
/opt/ant/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin

The installation and configuration procedure of Apache Ant on CentOS 7 is done without any glitches.

Tag : CentOS Ant
Comment
franciscoantonio
Oct 04 2017
Hi I'm facing issues to troubleshoot the follow issue:[root@localhost ~]# ant Error: JAVA_HOME is not defined correctly. We cannot execute /opt/java-1.8.0/bin/java [root@localhost ~]# The way is defined on profile : export JAVA_HOME=/opt/jdk1.8.0_144 export PATH=${PATH}:${JAVA_HOME}/bin export ANT_HOME=/opt/apache-ant-1.10.1 export PATH=${PATH}:${ANT_HOME}/bin
Add a comment
FAQ
Q
how to check the installed version of apache ant in terminal?
A
check the ANT version by executing the following command.
# ant &ndash version
Q
where to dwonload the package of apache ant using the terminal?
A
Apache Ant using its binary distribution from the official Apache web site. Execute the wget command followed by the download link
# wget redrockdigimark.com/apachemirror//ant/binaries/apache-ant-1.10.1-bin.zip
Q
What are its basic requirement needed for apache ant?
A
Apache Ant will require you to install Java, so make sure you have java installed on your machine.
Q
What was its current release of apache ant? How to keep track on it?
A
Use this link to check the current version of apache ant
"http://redrockdigimark.com/apachemirror//ant/binaries/"
Q
what is the required version of java for this apache ant?
A
Ant 1.9.* works with JDK 1.5 and higher, Ant 1.8.* works with JDK 1.4 and higher, Ant 1.7.* works with JDK 1.3 and higher, Ant 1.6.* works with JDK 1.2 and higher, Ant 1.2 to Ant 1.5.* work w