ANT’s best practices - V

11 May 2008

Do read the previous posts on this very topic before going through this one. I assume that you have some understaing of the ANT build precess.

Defining proper target dependency is also very helpful. Lets discuss this with a simple example. There is target call dist which depends on the jar target. The jar target depends on compile target which depends on prepare.

dist DEPENDS_ON jar DEPENDS_ON compile DEPENDS_ON prepare

Ant buildfiles define a dependency graph, which must be carefully defined and maintained.

Omitting dependencies in an effort to “optimize” the build is another common mistake. The right thing is to review the build files periodically to ensure that the dependencies are right and valid. Its not a good idea to compile a code that is not needed to be compiled. For instance, use made changes in the GUI and executed a target to compile the GUI target. The GUI target also compiled the EJB tier which was not required.

One should use properties for configurations. What should be defined as property? Any information that needs to be configured, or that might change, should be defined as an Ant property. The values that are used in more than one place in the buildfile can be defined as property. Many developers are confused about where to define these properties. You have following two choices:

Define the properties at the top of a buildfile.
Define the properties in a standalone properties file. This provides maximum flexibility.

The example presented below shows how to define properties in a build file:

<project name="sample" default="compile" basedir=".">
  <property name="dir.build" value="build"/>
  <property name="dir.src" value="src"/>
  <property name="jdom.home" value="../java-tools/jdom-b8"/>
  <property name="jdom.jar" value="jdom.jar"/>
  <property name="jdom.jar.withpath" 
                    value="${jdom.home}/build/${jdom.jar}"/>
    etc...
</project>

continued …

del.icio.us:ANT's best practices - V  digg:ANT's best practices - V  spurl:ANT's best practices - V  wists:ANT's best practices - V  simpy:ANT's best practices - V  newsvine:ANT's best practices - V  blinklist:ANT's best practices - V  furl:ANT's best practices - V  reddit:ANT's best practices - V  fark:ANT's best practices - V  blogmarks:ANT's best practices - V  Y!:ANT's best practices - V  smarking:ANT's best practices - V  magnolia:ANT's best practices - V  segnalo:ANT's best practices - V  gifttagging:ANT's best practices - V

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: ANT's best practices - V

Leave a Reply