This example illustrates how to call class file through build.xml file. The build.xml file is used to compile and run the java file and print the calculated value on command prompt. Here we are using only four targets, "clean" target deletes any previous "build" directory; second one is used to create "build" and "src" directories which depend on <target name="clean">, after execution of the clean target, this target will be executed; third one is used to compile the java file from "src" directory, it transforms source files in to object files in the appropriate location in the build directory and it depends on <target name="prepare">; forth one is used to run the class file and it depends on <target name="compile">. The debug keyword is used to find the error and optimize is used to find resources of source and destination directory. In the target run, fork="true" is used to display output and failonerror is used to display error report.
Simply copy and paste the following source code in the src directory and then run with ant command. The following output will be displayed:
Posted on: September 6, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles