Showing posts with label Ant. Show all posts
Showing posts with label Ant. Show all posts

Tuesday 9 February 2016

How to setup Apache Ant on Mac OS X

Folks, presenting a quick tutorial on how to setup the build tool Apache Ant on a Mac OS X machine.

Download the relevant ant archive version from Apache Ant homepage. For this example we download the latest v1.9.6.
Store it locally at any location you like; maybe like /Users/Username/apache-ant-1.9.6

Now lets edit the .bash_profile to define the ANT_HOME environment variable.

sudo vim ~/.bash_profile

Add the following lines to it (make sure to replace with your own username in the path):

export ANT_HOME=/Users/IroncladZone/apache-ant-1.9.6/
export PATH=$PATH:$ANT_HOME/bin

Now source ~/.bash_profile and restart terminal.

Check the above settings by looking up the ant version in terminal :

ant -v
Apache Ant(TM) version 1.9.6 compiled on June 29 2015
Trying the default build file: build.xml
Buildfile: build.xml does not exist!
Build failed

This means your ant is ready to use for builds. Going forward all you have to do is pass the build.xml to trigger the build.

Folks, watch out for this space for more basic to intermediate to advanced tutorials coming up soon.

Saturday 26 April 2014

Invoke Ant build from Maven

The jar created by the Ant build can be then attached to the project using the Build Helper Maven plugin.

Consider the following example snippet of the pom.xml

<plugins>
   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-antrun-plugin</artifactId>
         <version>1.7</version>
            <executions>
              <execution>
                <tasks>
                      Place any Ant task here
                </tasks>
             </execution>
           <executions>
   </plugin>
 </plugins>

If required, you can then attach the jar created by the Ant build to this Maven project using another plugin named "build-helper-maven-plugin".

This plugin has various goals like build-helper:add-resource and build-helper:attach-artifact

Tuesday 8 April 2014

Ant Mail Task

Ant provides a very useful Mail task which can be used in the build.xml to send email notifications.

Eg : 

<target name="mail-upload-notification">
<mail from="build_notification_email_group@company.com"
          tolist="build_receipient_list@company.com"
          subject="${war-file} has been uploaded to the server"
          message="The ${war-file} was uploaded to the ${ftp-server}" />
</target>

Detailed information about this task can be read here.

Thursday 13 March 2014

Quiet & verbose mode in Apache Ant

If you're using Apache Ant for building a project, you may notice that there are 2 logging switches available - quiet & -verbose. You may ask what is its significance.

-quiet switch tells Ant to print less amount of information to the console.

-verbose switch tells Ant to print extra additional amount of information to the console.

In better words, -quiet suppresses most messages produced by a build file. While -verbose increases the level of detailing by including details of each operation in the console. The -verbose switch can be extremely useful if you're debugging to try to find any errors. The verbose mode increases the traceability. Check the following link for additional information.

Friday 10 January 2014

Taskdef in Apache Ant

The 'taskdef' attribute can be used to add a task definition which would then be used in the existing project.

The taskdef tag is an important step you need to know, before I compose a post about automating deployments to tomcat.

It's syntax is similar to the typedef attribute.

Eg:

<taskdef name="start-tomcat" classname="org.apache.catalina.ant.StartTask" />

Observe how we set the classname attribute above.

Official information about Taskdef can be read here.

Tuesday 7 January 2014

Accept user input in Apache Ant

In Apache Ant, you can use the Input task in build.xml to accept user input. Check out the following illustration.

Eg:


As you see in the Input task, we specify the message that should get displayed asking for user input. 
The user input is then stored in a property named "my-name" in this case.
The valid arguments i.e the valid options are mentioned in the validargs parameter.

A detailed technote can be read here.

Friday 3 January 2014

Tstamp task in Ant

The Tstamp task in Apache Ant is used to set the DSTAMP, TSTAMP and TODAY properties. These properties can then be used in the build file, to generate filenames having the timestamps as strings.

Eg:

<tstamp>
        <format property = "current-date" pattern = "d-MMMM-yyyy" locale="en" />
        <format property = "current-time" pattern = "hh:mm:ss" locale="en />
</tstamp>

Note the nested element format which is used to set properties to a current time or date.

You could also add a prefix to these properties as follows:

Eg:

<tstamp prefix = "info">
</tstamp>

This will prefix the properties with the world info info. i.e. info.DSTAMP, info.TSTAMP, info.TODAY

Official detailed technote can be found here.

Friday 27 December 2013

Move Task - Ant

Move task in Ant is used to move a file or a directory or a set of files to a new directory.


  • Move task can also be used rename a single file (analogous to mv command in unix)
Eg:

<move file="test.txt" tofile="test_updated.txt" />


  • You can use to move a file to a specific directory as follows:
Eg:

<move file="test.txt" todir="/usr/var/move_here/" />


  • Move a set of files to a certain directory

Eg:

<move todir="/usr/var/mover_here/">
    <fileset dir="/my/src/dir_to_be_moved">
         <include name = **/*.jar >
         <exclude name = **/ant.jar">
     </fileset>
</move>  

A detailed official guide of the Move task and its parameters can be found here.



Rename build properties in Ant

It is possible to rename the build.properties file to something more specific to your environment. For instance, you can have separate build.properties file for DEV, QA, UAT or Production environment, if you want to.

You could rename it to lets say build-dev.properties or build-test.properties

Accordingly, rename the property tag in build.xml where you define the properties file.

Eg:

<property file="${user.home}/build-test.properties"/>

Thursday 26 December 2013

Increase memory used by JVM for Ant builds

Sometimes for builds using Apache Ant, we come across the Out of Memory error. In order to increase the memory used by JVM for the build, do the following:

Set ANT_OPTS=-Xms256m -Xmx1024m -XX:MaxPermSize=120m

Monday 23 December 2013

Pass arguments to build file - Apache Ant

In Apache Ant, we can pass arguments to the build file using the switch -D. We can define a value for a property from the command line using -Dname=value

Eg:

ant build.xml -Dx=5

Sunday 22 December 2013

Ant - read from build.properties

While performing builds using Ant, you must be aware about the build.xml file. The build.xml can read the parameter values from the build.properties file, which usually is one level up.

You have to define a property which mentions the properties file from which the script would read the values.

<property file = "build.properties" />
Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker