16 C
Texas
angeloma
Senior Writer and partner

How to install Apache Ant on CentOS 8?

Apache Ant functions as an important tool in the development of Java applications. With this tool, you will not have to worry about repetitive tasks in the process of compiling, and generating packages from source code in Java projects. So, this post is about installing Apaache Ant on CentOS 8.

Apache Ant

Apache Ant is an application created in Java sponsored by the Apache foundation that allows automating tasks of compilation and construction of projects. As it is made in Java it is common to use it for Java projects.

Thanks to Apache Ant it is possible to save a lot of time in medium size projects. It is similar to the make tool, the difference is that it uses a file called build.xml where you specify the rules that the application will use.

With this in mind, it is very likely that if you develop applications with Java, you will use Ant.

Let us work

Install Java on CentOS 8

- Advertisement -

The first step is to install Java. Java is a very popular development platform and is the basis for many projects worldwide.

Apache Ant is built with Java technology. This makes it necessary to install it for it to run.

OpenJDK 11 is available from the CentOS 8 repositories. To find it, run the following command:

:~$ sudo dnf search openjdk
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:41:14 ago on Mon Apr 6 10:34:18 2020.
==================================================================== Name & Summary Matched: openjdk ====================================================================
java-11-openjdk-demo.x86_64 : OpenJDK Demos 11
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos 8
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.x86_64 : OpenJDK Source Bundle 11
java-11-openjdk.x86_64 : OpenJDK Runtime Environment 11
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle 8
java-11-openjdk.x86_64 : OpenJDK Runtime Environment 11
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment 8
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-11-openjdk-devel.x86_64 : OpenJDK Development Environment 11
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment 8
java-11-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 11
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK 8 accessibility connector
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 8
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in single archive
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed in single archive
======================================================================= Summary Matched: openjdk ========================================================================
icedtea-web.noarch : Additional Java components for OpenJDK - Java browser plug-in and Web Start implementation

As you can see in the image above, Java 11 is available for installation from the official repositories through the OpenJDK project.

So to install it, run the following command:

:~$ sudo dnf install java-11-openjdk
1.- Install Java on CentOS 8
1.- Install Java on CentOS 8

Confirm the installation and it will start.

When it is finished, you can check the operation of Java with the following command:

~$ java --version
openjdk 11.0.6 2020-01-14 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.6+10-LTS, mixed mode, sharing)

So, Java is correctly installed.

Download and Install Apache Ant on CentOS 8

Apache Ant is a project sponsored by the Apache Foundation. This makes the download safe and free to use.

In this case, I will use an Apache mirror to download it.

:~$ cd /tmp/
:~$ wget -c http://mirrors.advancedhosters.com/apache/ant/binaries/apache-ant-1.10.7-bin.zip
--2020-04-06 11:18:58-- http://mirrors.advancedhosters.com/apache/ant/binaries/apache-ant-1.10.7-bin.zip
Resolving mirrors.advancedhosters.com (mirrors.advancedhosters.com)... 213.174.147.249, 2a02:b48:6:1::2
Connecting to mirrors.advancedhosters.com (mirrors.advancedhosters.com)|213.174.147.249|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10186279 (9.7M) [application/zip]
Saving to: 'apache-ant-1.10.7-bin.zip'

apache-ant-1.10.7-bin.zip 100%[=====================================================================================>] 9.71M 496KB/s in 25s

2020-04-06 11:19:25 (396 KB/s) - 'apache-ant-1.10.7-bin.zip' saved [10186279/10186279]

At the time of this tutorial, the latest stable version of Apache Ant is 1.10.7 When a new version is released all you have to do is update the command.

The downloaded version is in ZIP format. To unzip it, use the unzip command. If you don’t have it downloaded, just install it like this:

:~$ sudo dnf install unzip

Now, proceed to decompress it.

:~$ unzip apache-ant-1.10.7-bin.zip

And move the folder that is created to another location such as

:~$ sudo mv apache-ant-1.10.7/ /usr/local/ant

Now we have to make Ant available as a command to all users of the system. This will make it easy to use and run from any folder.

:~$ sudo nano /etc/profile

And add the following lines:

ANT_HOME="/usr/local/ant"
PATH="$PATH:/usr/local/ant/bin"
export ANT_HOME
export PATH
2.- Edit the profile file
2.- Edit the profile file

Then save the changes and close the editor.

Apply the changes made with the command:

:~$ source /etc/profile

Now, test it!

Test the Apache Ant installation

Once we have configured Ant, we must test if it works. The first test is to show the version of Ant using the command ant.

:~$ ant -version
Apache Ant(TM) version 1.10.7 compiled on September 1 2019

As you can see, the command works. Now place yourself in any folder and run ant.

:~$ ant

You’ll get the next output on the screen:

Buildfile: build.xml does not exist!
Build failed
3.- Testing Ant on CentOS 8
3.- Testing Ant on CentOS 8

This indicates that the command is working. All that remains is to create a build.xml file with the compilation instructions.

You can also check the command’s help:

:~$ ant --help
4.- Ant help
4.- Ant help

So, enjoy it.

Conclusion

Apache Ant is a very important application for many Java developers. So it might be a good idea to have it if you want to start with Java.

Please share this post and join our Telegram channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article