The Artima Developer Community
Sponsored Link

Java Buzz Forum
Awesome Ant

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
John Topley

Posts: 233
Nickname: johntopley
Registered: Jul, 2003

John Topley is embarking on a journey to become a J2EE master.
Awesome Ant Posted: Aug 7, 2003 1:12 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by John Topley.
Original Post: Awesome Ant
Feed Title: John Topley's Weblog
Feed URL: http://johntopley.com/posts.atom
Feed Description: John Topley's Weblog - some articles on Ruby on Rails development.
Latest Java Buzz Posts
Latest Java Buzz Posts by John Topley
Latest Posts From John Topley's Weblog

Advertisement

The latest edition to my J2EE armoury is Apache Ant, which I've spent the past few days investigating. For those who don't know, Ant—which stands for Another Neat Tool—is a Java automated build tool. It uses an XML configuration file (or files) and can be used to perform a multitude of tasks. Tasks such as compiling Java source code, creating JAR, WAR or EAR archives, copying or moving files, generating Javadoc pages, deploying files to an application server, even running unit tests. And if Ant's set of built-in tasks isn't enough for you, you can extend it by writing your own Java classes. Ant build files can also call other Ant build files, which means that large projects can be more easily partitioned and managed.Apache Ant Logo

I did encounter one or two problems using Ant but only because I'm a newbie. I give details here in case anyone else gets caught out like I did.

I was using the jar task to create a Java archive and I was puzzled as to why I was ending up with two copies of each class in the JAR file. I had a block of code similar to this:

<jar destfile="${dist.jarfile}"
        basedir="${build.classes.dir}">

  <fileset dir="${build.classes.dir}">
    <include name="**/*.class"/>
    <exclude name="**/*Test*"/>
  </fileset>
</jar>

—I ran Ant using the -debug switch which generated a copious amount of output and made what was happening obvious. Re-reading the documentation confirmed it. The jar task forms an implicit Ant FileSet, so all I needed was:

<jar destfile="${dist.jarfile}"
        basedir="${build.classes.dir}">

  <include name="**/*.class"/>
  <exclude name="**/*Test*"/>
</jar>

The other problem I came across prevented compilation of some source files because the compiler couldn't find some of the classes that the source depended upon. This took me a fair while to solve but it turned out to be because I'd specified an incorrect basedir attribute in my jar task, which meant that all of my .class files within my JAR were a directory deeper than they should have been!

In other words, instead of telling jar to start from the /classes directory, I'd told it to start from the project's root directory, meaning that the path to the compiled classes started with classes instead of gov which is the start of my package hierarchy. Doh!

I'm totally impressed with Ant and shall be using it for all my J2EE projects from now on. Although most Java IDEs now feature Ant integration, what it's crying out for is a decent GUI build file editor, i.e. an antidote to using Notepad!

Read: Awesome Ant

Topic: RTSJ Previous Topic   Next Topic Topic: Ah, that's your name then

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use