Thursday, June 2, 2011

Ant Basics

The documentation for the installation is written under the assumption that the reader has some experience of installing software on computers and knows how to change the operating environment of the particular operating system they are using. The documents entitled Configuring A Windows Working Environment and Configuring A Unix Working Environment are of use to people who need to know more.

  1. Download the binaries from http://jakarta.apache.org/ant/index.html, unzip them to a suitable directory.

  2. Append /path/to/ant/bin to the PATH environment variable.

  3. Append the .jar files in /path/to/ant/lib/ to the CLASSPATH environment variable. Set JAVA_HOME to point to the location of the JDK installation on the machine that the software is being installed on. Append/path/to/jdk/lib/* to the CLASSPATH environment variable.

The installation instructions provided with the Ant software installation download are clear enough to warrant abstaining from writing any more about the installation here. Refer to/path/to/ant/docs/manual/install.html.

An Ant build file comes in the form of an XML document, all that is required is a simple text editor to edit the build file(s). An editor that provides XML syntax highlighting is preferable. The Ant installation comes with a JAXP-Compliant XML parser, this means that the installation of an external XML parser is not necessary.

A simple Ant example is shown below followed by a set of instructions indicating how to use Ant. It is recommended that the reader follow these instructions to gain some experience in using Ant.

1

Since Ant build files are XML files the document begins with an XML declaration which specifies which version of XML is in use, this is to allow for the possibility of automatic version recognition should it become necessary.

2

The root element of an Ant build file is the project element, it has three attributes.

  • name: The name of the project, it can be any combination of alphanumeric characters that constitute valid XML.

  • default: The default target to use when no target is specified, out of these three attributes default is the only required attribute.

  • basedir: The base directory from which any relative directories used within the Ant build file are referenced from. If this is omitted the parent directory of the build file will be used.

3

 

Friday, April 8, 2011

Giving Version / Build information in Java project

For several of my projects I capture the subversion revision number, time, user who ran the build, and some system information, stuff them into a .properties file that gets included in the application jar, and read that jar at runtime. The ant code looks like this:



<property name="version" value="1.23"/>

<target name="buildinfo">
<tstamp>
<format property="builtat" pattern="MM/dd/yyyy hh:mm aa" timezone="America/New_York"/>
tstamp>
<exec executable="svnversion" outputproperty="svnversion"/>
<exec executable="whoami" outputproperty="whoami"/>
<exec executable="uname" outputproperty="buildsystem"><arg value="-a"/>exec>

<propertyfile file="path/to/project.properties"
comment
="This file is automatically generated - DO NOT EDIT">
<entry key="buildtime" value="${builtat}"/>
<entry key="build" value="${svnversion}"/>
<entry key="builder" value="${whoami}"/>
<entry key="version" value="${version}"/>
<entry key="system" value="${buildsystem}"/>
propertyfile>
target>


Starting and Stopping of tomcat using ANT command

Starting of tomcat:

Starting of Tomcat


Stopping of tomcat
value="-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"/>