02.03.2020
Posted by 

In this tutorial, i will show you how to build your Java Application with Apache Ant. At 90% of our test is automated and to do so will need an automated means of build our project. This is when Apache Ant comes in handy. There are several types of Java build tools such as Maven, Gradle etc. Each of this build tools have their strengths and weaknesses.

  1. Apache Ant Download For Mac

What is Apache Ant As I explained above, it is an automated build tool for Java software build processes and also helps you manage your project from command line. Prerequisite. You need to have Apache installed.

You can get it from. You need to have JDK installed. You can get it from. Have a Java IDE installed (I will be using ) Open your IDE and Create a new Java Project.

(I will call mine AntProject) Note When you create a NetBeans Project, it automatically generates an Ant file called build.xml which will compile, clean and build your project for you. I will go ahead and show you how you can create the build file your self so you can do a whole lot of customisation to your project. In Netbeans, switch to the File view and create a new xml file.

Apache Ant Download For Mac

I will call mine jbuild.xml. Delete the root tags and add project and description tag to the xml file so it looks like mine.

Description of your project We will give our project a name. #!/bin/bash #1.4 export ANTHOME= /PDFdata /library /apacheant / export PATH= $ANTHOME /bin: $PATH ant -buildfile jbuild.xml main if $? -eq 1 ; then echo 'Failed on Build' exit 1 fi #!/bin/bash #1.4 export ANTHOME=/PDFdata/library/apacheant/ export PATH=$ANTHOME/bin:$PATH ant -buildfile jbuild.xml main if $? -eq 1 ; then echo 'Failed on Build' exit 1 fi if on Windows, click on Start – Right click on computer – Advance settings – Environmental Variables and set variables for ANT.

Before you add the path to the existing path, make sure the exiting path has a semicolon at the end, if not add one before you paste the path. Once done open command line and type in ant.

You should see something like this. Create a batch file and paste this code. @ECHO OFF ant -buildfile jbuild.xml main IF ERRORLEVEL 1 ( echo 'Failed build' exit 1 ) @ECHO OFF ant -buildfile jbuild.xml main IF ERRORLEVEL 1 ( echo 'Failed build' exit 1 ) As you can see in both scripts, we call ant then specify the build file (jbuild.xml – the one we created) then we call the main target from the build. You can also run without calling the main target as we specified it as default in our project tag. Your project should be looking like this with either bash or bat file.

Mac

Now open command line and navigate to the AntProject directory. On MAC/LINUX, type in chmod +x build.bash hit enter then./build.bash and enter On Windows, type in build.bat and hit enter You should now see all the build steps in your console and you build should be Successful.

Head over to NetBeans and you should see a staging directory which contains the compiled class in bin folder and jar in dist folder. Hopefully you have found this quick guide useful. In the next article, I will show you how to setup Jenkins which is an open source continuous integration tool. We will then use both to perform some automated static Analysis on our code base. If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (, and ) or the.