September 24, 2013

Ant Build Tool : Quick Notes

Ant Script for JAVA Developers

1) Simple Ant Script for Clean , Compile and jar generation adding Manifest information to jar


    
   	 init called ..
    

    

    
   	 Delete All Class Files ..
   	 
   		 
   	 
   	 
    

    
   	 Delete All Jar Files ..
   	 
   		 
   			 
   		 
   	 
   	 
    

    
   	 Compile All Java Files ..
   	 
   		 
   		 
   			 
   				 
   			 
   		 
   	 
    

    
   	 Generate Jar File ..
           
   	 
   	
   	    
                
                
          
        
    

Note :- All folder path are relative to basedir . Here is basedir=”.”
Note :- the values at class-path are separated by space

2) Using Property in Ant Script

  	
   	 Start
   	 
   	 Property Value.. ${show}
    


3) Reading From Property File


    

4) Current Time Stamp in Ant Script

    	
   		 
   		 
   		 
   		 
   	 
   	 Current Time is : ${current.time} 





5) Directory Opertaions
Make dir

           
   	 

      Delete Dir
    	
   		 
   			 
   		 
   	  
File/Direcotorr Rename


Copy files
 
   
   		 
   			 
   		 
   	 

6) Ant Script and Svn

SVN Checkout

  
   	 
   		 
   		 
   		 
   		 
   		 
   		 
   		 
   			 
   				 
   			 
   		 
   	 
     

Note :- for https:/ type svn
7)File uploads and Ant Script

	
   	 
   	 
   	 
   		 
   	 
    

    
   	 
   		 
   	 
    

8) Variable of Varible in Ant Scipt


   	 
              	hi
   	 

   		 
   		 
   		 
   		 
   			 
   			 
   			 
   			 
   				 userid is :- ${userid}
   				 password :-${password}
   			 
   		 
   			 Lifecylce Specific Information Feteched...
   		 
   		 
   	 
   	 
   	 
   		 
   			 Lifecylce Specific Information Feteched...
   		 
   	 
    

9)creating war and zip file in ant script


   	 
   		 
   			 
   			 
   		 
   	 
   	 
   		 
   	 
    

10) Creating Custom Ant Tasks

	
   	 custom task..
   	 
   		 
   			 
   			 
   				 
   			 
   		 
   	 
   	 
   	 
   	 Password Decrypted Successfully... ${sftp.password}
    
    
    
AntScriptUtils.java
    
package com.example;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;



public class AntScriptUtils extends Task {
    private String pass;
    String decryptedPassword = null;

    // The method executing the task
    public void execute() throws BuildException {

    
   	 try {
   		 decryptedPassword = decrypter.decryptValue(pass);
   		 getProject().setProperty("dPassword", decryptedPassword);

   	 } catch (PropertyEncrypterException e) {
   		 e.printStackTrace();
   		 ErrorLogger.fatal("Error : ", e);
   	 }
    }

    // The setter for the "message" attribute
    public void setMessage(String msg) {
   	 this.pass = msg;
    }

    public static void main(String[] args) {
   	 new AntScriptUtils();
    }

}

Required Jar files for ant’s different task
antlr-runtime-3.1.3.jar commons-net.jar ganymed.jar jna.jar
jsch-0.1.44.jar sqljet.1.0.4.jar svnant.jar svnClientAdapter.jar
svnjavahl.jar svnkit.jar svnkit-cli.jar
svnkit-javahl.jar trilead.jar

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.