Using Ant to execute class file
This build.xml file is used to compile and run the java file and print the value on command prompt. Here we are using five targets, the "clean" target deletes any previous "build", "classes" and "jar" directory; second one is used to create all necessary directories and it depends on <target name="clean">; third one is used to compile the java file from "src" directory to transform source files in to object files in the appropriate location in the build directory and it depends on <target name="prepare">; fourth one is used to create the jar file and it depends on <target name="compile">, it means that after completion of compile target, it will be executed; fifth one is used to run the jar file and it depends on <target name="jar"> and finally <target name="main"> is used to specify the default project name, it means that when the program will be run, it will be called first and it depends on <target name="run">.
|
If you run this build.xml file using ant command, then the following output will be displayed.
In this output display, the class name Roseindia is not found by the compiler. Create a java file as shown below and put it in the src directory, and again run it with ant command. The following output will be displayed.
|