We will execute a simple Ant script today. While most of what I am going to present in this post and the next post is just an eye opener to Ant, you can get much in depth details, examples and tutorials by Googling around. The example in this post and the coming post(s) assume that you know Java. Download this small project that has the source and ant script file to package a Hello World program. The default distribution type for any java application is a java archive file, so we are going to build that. To execute the script you need to download Ant and configure it. Once you have set it up, go to DOS prompt and type the following command.
If you have setup Ant correctly, you should be seeing an output something like this.
Apache Ant version 1.6.5 compiled on June 2 2005
This example runs unit tests using JUnit, so once you extract the zip file, create a folder called lib and copy the junit-3.8.1.jar into the lib folder (for want of space I removed it from the zip). This step is important, otherwise the build will fail.Once you have completed the above steps, assuming you have extracted the project under
c:\HelloWorld, at the HelloWorld folder in the DOS prompt execute,
If you installed and configured everything correct you should see a successful build. Goto the target folder and see if HelloWorld.jar file is there. To make sure you can execute the HelloWorld application from the jar, execute the following command.
c:\HelloWorld\target\>java -cp .\HelloWorld.jar com.compassites.HelloWorld
Now with this basic script, you can keep adding your source file and with one command you can package all your source into a jar that you can distribute. We will look into the build.xml and understand the script in the next post.