This post is based on Tutorial: Hello World with Apache Ant
Today we’ll try Apache Ant.
Apache Ant is a software tool for automating software build processes. Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. For simple, Ant’s first advantage is the separation of source files and result files.
Before start it, you, of course, will need to install Apache Ant first.
And… again before we start Ant, let’s try to build HelloWorld project that its result files to be separated from source files. If you don’t want to try it but directly start Ant, go Start Apache Ant – 2/2.
I’ll use and empty Git initiated directory that I made last time, Create a Project in GitHub. Below is brief of it for people who tried it but didn’t keep the directory.

We’ll make source directory, src, and package directory, com, in src and a java file, HelloWorld.java, in com. as below.

open HelloWorld.java and write basic code as below.

Compiling a java file in source directory from project directory will be little tricky.
As picture bellow, go project directory and make build directory, and classes directory in it. and compile as below command.
javac -sourcepath src -d build\classes src\com\HelloWorld.java
this command will compile HelloWorld.java in directory src\com and store resulting HelloWorld.class file in build\classes directory. Then excute it as below command.
java -cp build\classes com.HelloWorld

class file is created as below.

Now we will create jar file. jar file is archive file that contains one or number of java packages. This comes handy when your java program consist of number of packages and java files. In order to create jar file, you need Manifest file as below. It means executing jar file will execute main function in com.HelloWorld.
MARK there must be an additional line in the end. So the total number of line is 2.

make a directory jar in build directory and create jar file.
jar cfm build\jar\HelloWorld.jar Manifest.txt -C build\classes .
Execute it
java -jar build\jar\HelloWorld.jar

All those things are what we have to do to separate result files from source files.
Let’s try Ant and see how things go simpler and easier.
Start Apache Ant – 2/2