Practical
Embedded Java

Tools: Ant


A practical engineering approach to using embedded Java in real-world applications.


...



 

Ant is:

a wonderful too which helps you build, test, and deploy (Java or other) applications. Ant is a more modern alternative to the C "make" utility. Ant is now part of the Apache open source project, and was originally written to assist with the Apache Tomcat project builds. Ant is written in Java. It's worth learning in some detail, which means you need a reference text. Several are available.

History:
Ant was invented by James Duncan Davidson. Here is his website and blog. Ant 1.0 was released in March 2000.
References:
I highly recommend the book "Java Development with Ant". It is a tutorial as well as a comprehensive reference. The index is pretty good - you can usually find useful information on a specific topic fairly quickly.
Get Ant and options:
http://ant.apache.org/ is the current Ant website.
TINI Ant is a SourceForge project: http://tiniant.sourceforge.net/
netcomponents.jar is at http://www.savarese.org/oro/downloads/index.html#NetComponents
mail.jar for the mail task: http://java.sun.com/products/javamail/
activation.jar for the mail task: http://java.sun.com/products/javabeans/glasgow/jaf.html

Ant Concepts
Ant uses XML build files. If you are new to XML (like me) this may seem a little strange, but since XML is so logical and self-documenting, it quickly makes a lot of sense. An Ant build file contains one project, which itself contains multiple targets. Each target contains tasks.Targets can depend on each other, so building one target may cause others to be built first.

Example: an Ant target and task
Here is a simple target from the BenchMark build file. This target depends on the "init" target and has one task (javac). It uses a system environment variable to locate the TINI home directory and locate the tiniclasses.jar file. It uses the javac compiler to compile all .java files in the "src" subfolder and put the resulting .class files in the folder called "tinibuild". It also emits some messages. Don't be confused by the javac "target" option here - this is a compiler switch and has nothing to do with Ant targets.
<target name="tini_compile" depends="init">
	<echo>Compiling for TINI</echo>
	<echo message="TINI_HOME is set to ${env.TINI_HOME}"/>
	<echo>javac should have the -target 1.1 switch</echo>
	<javac target="1.1"
		bootclasspath="${env.TINI_HOME}/bin/tiniclasses.jar"
		srcdir="src"
		destdir="tinibuild" />
	<echo>TINI Compilation Complete</echo>
</target>

Ant Tasks (there are four kinds)
Core Ant tasks are built into the basic Ant installation and include javac, jar, etc. Optional tasks ship with Ant in its optional.jar library but require external support. Third-party tasks (such as TiniAnt) can be easily added to your Ant installation, and you can write custom Ant tasks yourself.

Optional Ant Task FTP

The optional Ant task FTP task requires that "optional.jar" be installed in the ANT_HOME\lib folder. No problem, I thought, it's there. But when I tried to write a target using the FTP task I got this runtime error:

BUILD FAILED
file:D:/PROJECTS/BenchMark/build.xml:76: Could not create task or type of type: ftp.
Ant could not find the task or a class this task relies upon.

Well, I can see "FTP.class" in the optional.jar file, so what's up - why can't Ant "find the task"? It turns out that ftp and telnet tasks require additional libraries. It's not terribly easy to find this in the Ant javadocs under "Library Dependencies", and even harder to find the URL for netcomponents.jar (so see the links above for a shortcut).

So I copied NetComponents.jar into the Ant /lib folder and - voila - now the FTP task works:
tini_load:
      [ftp] Opening FTP connection to 166.70.144.54
      [ftp] connected
      [ftp] logging in to FTP server
      [ftp] login succeeded
      [ftp] sending files
      [ftp] transferring D:\PROJECTS\BenchMark\tinibuild\BenchMark.tini
      [ftp] File D:\PROJECTS\BenchMark\tinibuild\BenchMark.tini copied to 166.70.144.54
      [ftp] 1 files sent
      [ftp] disconnecting
     [echo] TINI FTP download complete

 
Systronix® 939 Edison St, Salt Lake City, Utah, USA 84111
Tel +1-801-534-1017, Fax +1-801-534-1019
contact us     Time Zone: MDT (UTC-6)
 

Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Systronix is independent of Sun Microsystems, Inc.
TStik, JStik, JCX, JStamp, JSimm, JDroid, and JRealTime are trademarks of Systronix, Inc.
1-Wire, iButton and TINI are trademarks of Dallas Semiconductor
Simmstick is a trademark of Dontronics
LEGO® is a trademark of Lego A/S, Denmark