View RSS Feed

Ant

Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects.

  1. Ant Paths

    by , 11-21-2011 at 06:05 PM (My Java Tips)
    If you specify the PATH and the CLASSPATH type references using any of this, that is ":" and ";" as a separator characters, Ant can convert the separator to the correct character of the operating system in the use.


    A nested element can be used wherever path like values need to be specified. See the example below.
    Java Code:
        <classpath>
    <pathelement path="${classpath}"></pathelement>
    <pathelement location="lib/helper.jar"></pathelement>
    ...
    Categories
    Ant
  2. Ant (an introduction)

    by , 11-19-2011 at 05:54 PM (My Java Tips)
    Ant is an open source software written in Java language. This is an Apache product. Ant is cross platform and portable. Ant is similar to make utility. It is used to automate software build processes to essentially build Java projects. However, at the same time it should be remembered that Ant is not a programming language. Ant uses XML to describe build processes. This XML file is called as build.xml.


    Ant can compile source code as well as Ant can package compiled source code and ...
  3. Simple Ant script

    by , 11-19-2011 at 05:49 PM (My Java Tips)
    Let us see how to write a simple ant script for a Java application. Write a simple HelloWorld Java class


    HelloWorld.Java
    Java Code:
    public class HelloWorld
    {
     	public static void main(String args[])
      	{
       		System.out.println("HelloWorld!");
      	}
    }
    By default Ant uses build.xml as the name for a buildfile. This is the build.xml.
    Java Code:
    <project default="compile">
    
      	<target name="compile">
    ...
    Categories
    Ant
  4. Ant Project

    by , 11-19-2011 at 05:43 PM (My Java Tips)
    In this post, I will present a sample build.xml file for a simple Java "Hello, world" application and will explain the ANT project.


    Java Code:
    <project name="HelloWorld" default="compile">
    
      	<target name="compile">
        		<javac srcdir=".">
      	</javac></target>
    
        	<target name="run" depends="jar">
        		<java classname="HelloWorld">
    ...
    Categories
    Ant
  5. ANT Targets and Tasks

    by , 11-19-2011 at 05:39 PM (My Java Tips)
    In this post, I will talk about ANT targets and tasks.


    <strong>Targets</strong>
    Each buildfile contains at least one target within the project. One target can be dependent upon the another target.
    Java Code:
    <target name="A">
    <target name="B" depends="A">
    <target name="C" depends="B">
    <target name="D" depends="C">
    <target name="E"
    ...
    Categories
    Ant
  6. ANT properties

    by , 11-18-2011 at 07:23 PM (My Java Tips)
    A project in a build.xml can have a set of properties. This property has a name and a value. In which the name of the property is case-sensitive. Properties can be used in the value of task attributes. It is done by putting the property name between "${" and "}" in the attribute value. For example, if there is a "builddir" property with the value "build", then this could be used in an attribute like this: ${builddir}/classes. At run-time this is resolved as ...

    Updated 11-18-2011 at 07:26 PM by Java Tip

    Categories
    Ant
  7. ANT's best practices

    by , 11-07-2011 at 07:28 PM (My Java Tips)
    ANT makes building complex Java applications easier. But many people argue that managing ANT scripts is itself a cumbersome task and involves a lot of effort. In the next few posts, I will talk about how one can adopt best practices for creating and managing ANT scripts that will make the life of developers and configuration managers easier.


    First thing is, one should follow a consistent style while writing XML for ANT files. If you format your ANT script, it will be visually appealing ...
    Categories
    XML , Ant
  8. ANT (Example)

    by , 11-07-2011 at 06:55 PM (My Java Tips)
    This post is all about an ANT example. I will present an ANT build script that will compile a project, and will generate a JAR file.



    I will name the project as Project X and will provide some useful description.

    <!--?xml version="1.0"?-->
    <project default="dist" name="Project X">
    <description>Test project</description>
    </project>

    Now is the time to define the properties. ...
    Categories
    Ant , XML
  9. Ant exec task

    by , 11-07-2011 at 06:19 PM (My Java Tips)
    To execute a system command from Ant, exec is used. Since different operating systems have different commands, therefore OS commands (if used), will restrict the build script to a particular operating system.


    One cannot interact with the forked program and if any attempt to read input in the forked program is made, an EOF (-1) will be thrown.

    The task delegates to Runtime.exec which in turn apparently calls ::CreateProcess. Generally, batch files (.bat) cannot by executed ...
    Categories
    Ant , XML
  10. Using a custom task in Ant

    by , 11-06-2011 at 06:53 PM (My Java Tips)
    It is assumed that you have already defined a custom Ant task and wish to use it. In this post, I will show you how to do so.




    You first need to define the task by giving it a name and telling Ant the classfile that implements it and any classpath setting required to locate that classfile. This is done using the taskdef task, like so:

    <taskdef name="fileparser">classname="FileParser"
    classpath="."/&gt; ...
    Categories
    Ant , XML
  11. Defining custom tasks in ANT

    by , 11-06-2011 at 06:49 PM (My Java Tips)
    Ant provides various core and optional tasks which you use to automate the build process. Very seldom, you need to define your own customized tasks.


    To implement a simple custom task, you need to extend the org.apache.tools.ant.Task class and override the execute() method. Follow the sample below:

    Java Code:
    import org.apache.tools.ant.BuildException;
    import org.apache.tools.ant.Task;
    public class FileSorter extends Task {
    // The method executing the
    ...
    Categories
    Ant