How do I use a file?
Author: Deron Eriksson
Description: This tutorial describes how to use an Ant file.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.1

Page:    1 2 >

A properties file allows you to move properties out of your build.xml file. This can be a useful way of extracting out and storing the configurable portions of the AntSW tasks that you create.

To use a properties file in your Ant build.xml file, all you need to do is include a property in your build.xml file with the name of the properties file specified by the file attribute, as shown below:

<property file="" />

The build.xml file used in this tutorial has the following targets: warW, ftpW, mail-upload-complete, and all. The 'war' target build the project's war file, 'ftp' uploads the war file to the server, and 'mail-upload-complete' sends an email to a local email server account notifying me that the war file has been uploaded to the server. The 'all' target executes 'war', 'ftp', and 'mail-upload-complete'.


<?xml version="1.0" encoding="UTF-8"?>
<project name="tomcat-demo" default="war" basedir=".">
	<property file="" />
	<property name="war-file-name" value="${project-name}.war" />
	<property name="source-directory" value="src" />
	<property name="classes-directory" value="bin" />
	<property name="web-directory" value="web" />
	<property name="web-xml-file" value="web/WEB-INF/web.xml" />
	<tstamp prefix="build-info">
		<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
		<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
		<format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />
	<property name="build-directory" value="build" />

	<property name="ftp-remotedir" value="uploaded-wars/${project-name}/${build-info.year-month-day}" />
	<target name="war" depends="">
		<mkdir dir="${build-directory}" />
		<delete file="${build-directory}/${war-file-name}" />
		<war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
			<classes dir="${classes-directory}" />
			<fileset dir="${web-directory}">
				<!-- Need to exclude it since webxml is an attribute of the war tag above -->
				<exclude name="WEB-INF/web.xml" />
				<attribute name="Built-By" value="${builder}" />
				<attribute name="Built-On" value="${build-info.current-date}" />
				<attribute name="Built-At" value="${build-info.current-time}" />

	<target name="ftp" depends="" description="upload war file to server">
			server="${ftp-server}" remotedir="${ftp-remotedir}"
			userid="${ftp-userid}" password="${ftp-password}"
			action="mkdir" verbose="yes">
			server="${ftp-server}" remotedir="${ftp-remotedir}"
			userid="${ftp-userid}" password="${ftp-password}"
			action="send" verbose="yes" depends="yes">
			<fileset file="${build-directory}/${war-file-name}" />

	<target name="mail-upload-complete">
		<mail from=""
		      subject="${war-file-name} was uploaded to the server"
		      message="The ${war-file-name} file was uploaded to ${ftp-server} in ${ftp-remotedir}"/>

	<target name="all" depends="war,ftp,mail-upload-complete">

(Continued on page 2)

Page:    1 2 >