Typically, the ant build file build.xml should be in the project's underlying directory. You can freely use other file names or other locations in the build file.
In this exercise, create a file named Build.xml anywhere on your computer.
<?XML version= "1.0"?> <Projectname= "Hello World Project"default= "Info"> <Targetname= "Info"> <Echo>Hello World-welcome to Apache ant!</Echo> </Target></Project>
Note that there should be no empty lines or spaces before the XML declaration. The processing instruction target matching "[Xx][mm][ll]" is not allowed-if you do this, this may be caused by an error message when you run the ant build.
All build files require project elements and at least one target element.
The XML element's project has three properties:
A goal is a collection of tasks to run as a unit. In our example, we have a simple goal to provide an informational message to the user.
The target can be dependent on other targets. For example, a deployment target might have dependencies on encapsulated objects and package targets that might have dependencies on compile targets, and so on. Dependencies are expressed using dependency properties. For example:
<target name= "Deploy" depends= "pacakge" >
....
</target>
<target name= "pacakge" depends= "Clean,compile" >
....
</target>
<target name= "clean" >
....
</target>
<target name= "Compile" >
....
</target>
The target element has the following properties:
The Echo task in the example above is to print a message for a simple task. In our example, it prints out the Hello World message.
To run the ant build file, open a command prompt and navigate to the folder where the Build.xml file is located, and then enter Ant info. You can also just enter ant instead. Both work because the information is the default target in the build file. You should see the following output:
Java Share 20th day (Build.xml syntax and notation)