

Here, we used a RHEL/CentOS 7 machine, but the same build.xml file can be used to compile and build our Java application on any other platform.Apache Ant is distributed under the Apache Software License which is a fully-fledged open source license certified by the open source initiative. We have successfully compiled and build our Java application by using Apache ANT commands. Building jar: /root/TestApp/build/jar/test.jar Compiling 1 source file to /root/TestApp/build/classes Created dir: /root/TestApp/build/classes # vi build.xmlĭefine some basic Targets and Tasks therein. Now, we will compile the same application by using Apache ANT commands.Ĭreate an Apache ANT Build File build.xml for our project. We have successfully compiled our Java code and then build a JAR file by using Java commands. # jar cvfm build/jar/test.jar mymanifest -C build/classes/. # echo "Main-Class:test.TestApp" > mymanifestĬreate a JAR file now.

To create a JAR, we need to create a JAR manifest for our Java Project. Since, our application is running fine, we can now create a JAR file from compiled classes. # javac -sourcepath src -d build/classes src/test/TestApp.java ("Testing Apache Ant.") Ĭompile TestApp.java and check for any possible errors. # vi src/test/TestApp.javaĪnd write some Java code here. # cd TestAppĬreate a file in src/test directory. TestApp.īuild/classes directory is used for place the compiled Java classes.īuild/jar directory is used to generate JAR (Java Archive) from the compiled Java classes.Ĭheck the directory structure.

Src/test directory is used for keeping the source code of our Java Application i.e. Let's create required directory structure for our project. We will first create a simple Java application and then compile and build the JAR by using Java commands. # yum install -y antĪpache ANT requires Java Development Kit (JDK) therefore, it has installed the available version of OpenJDK from yum repository. Install Apache ANT package with yum command.

Apache ANT (Another Neat Tool) is a Java Library and Command-line tool to automate software build processes.
