Android Tutorials - Herong's Tutorial Examples - Version 3.02, by Dr. Herong Yang
Preparations on Using Apache Ant Tool
This section describes how to prepare yourself to use the Apache Ant tool: create proper folder structure; define smaller build steps; put build steps into an Ant build file; implement each build step with Ant commands.
In order to use Apache Ant to help you to build a Java application, you need to prepare the following items:
1. Organize your application files in a nice folder structure. Here is an example:
.\ - Home folder to store all files of the application .\src - Source folder to store Java source files .\build - Build output folder .\build\classes - Class folder to store resulting class files .\build\jar - JAR folder to store resulting JAR files
2. Divide the build process into smaller steps. Here are some examples of build steps:
clean - To clean up the build output folder compile - To compile all Java source files into class files jar - To build the JAR file from class files run - To execute the main class from the JAR file
3. Define all build steps in an Ant build file called .\build.xml. The build file is an XML file with the following structure:
<project> <target name="build_step_1"> build_command_1 build_command_1 ... </target> <target name="build_step_2"> ... </target> ... </project>
4. Implement each build step with Ant commands. Here is an example of implementing the "compile" build step with 3 Ant commands:
<target name="compile"> <delete dir="build/classes"/> <mkdir dir="build/classes"/> <javac srcdir="src" destdir="build/classes"/> </target>
After finishing implementing all build steps in the build file, you are ready to run the Ant tool to build your application. See next tutorial for a simple build file example.
Last update: 2015.
Table of Contents