Skip to main content

What is Apache Ant ("Another Neat Tool") in java?(ANT Part-1)



Apache Ant ("Another Neat Tool") is a  build tool with special support for the Java programming language however it may be used for regarding everything. Ant is platform-independent. Ant is especially sensible at automating difficult repetitive tasks and so is well matched for automating standardized build processes. Ant accepts directions within the type of XML documents so is extensile and simple to take care of.So you can say it is a xml file you running by the help of Ant.

An ant build file comes within the sort of an XML document, all that's needed may be a straightforward text editor to edit the build file(s). an editor that gives XML syntax lightness is desirable. The ant installation comes with a JAXP-Compliant(Which is XML parser) ,this implies that the installation of AN external XML computer program isn't necessary

For Installation 

1)You will need to download a file apache-ant-1.7.0-bin.zip
2)Extract it 
3)Here you will get "bin" folder
4)In "bin" run the ant.bat file from cmd.


Now let us try this with a simple build.xml for this.

1)create a file in notepad or any other file editor

2)copy the below code in that

<?xml version="1.0"?>
   <project name="My First Project" default="whatsup">
       <target name="whatsup">
          <echo>Hi this is my first ant build file</echo>
       </target>
   </project>

3)Save this as build.xml file(in ant bin directory where ant.bat is present)
apache ant

4)You can run this from a DOS  command prompt by typing

  ant
Ant will search for the build file in the current directory and run the build.xml file.

5)your out put will


Buildfile: build.xml
  
  whatsup: 
     [echo] Hi this is my first ant build file!
  
  Build Successful
  Total time 0 seconds

If you have many targets which you have run or execute in series then you can use depends attribute.
The depends attribute may be enclosed within the target tag to specify that this target needs another target to be executed before being executed itself. Multiple targets may be nominal and separated with commas.

<target name="ab" depends="bc, cd,de">

<?xml version="1.0" encoding="UTF-8"?>

 <project default="3">
     <target name="1">
        <echo>Running first</echo>
     </target>
  
     <target name="2" depends="1">
        <echo>Running second</echo>
     </target>
  
     <target name="3" depends="2">
        <echo>Running third</echo>
     </target>
  </project>

Buildfile: build.xml
  
  one:
     [echo] Running first
  
  two:
     [echo] Running second
  
  three:
     [echo] Running third
  
  BUILD SUCCESSFUL
  Total time: 0 seconds


Ant Task – one thing that ant will execute like a compile, copy or replace. Most tasks have much convenient default values. See the ant manual for an entire list of tasks.

Ant Target – a hard and fast series of ant tasks in an exceedingly nominal order that may depend on alternative named targets. Targets will depend solely on alternative targets, not on projects or tasks. A target represents a specific item to be created, it can be one item sort of a jar, or a group of things, like classes.

Ant Project – a set of named targets that may run in any order looking on the time stamps of the files within the file system. every build file contains one project.


Here are a few things to note:

1.The Begin and finish tags for project (<project> and </project>) MUST Begin and end the file.

2.The tag project MUST have an attribute called default which is the targets called first.

3.There should be at least one target in each build file.

4.The Begin and finish tags for <target> and </target> must  match EXACTLY.

5.Each target should  have a name.

6.Targets will only depend  on other targets and reference them by their name(target name). it NEVER depend on projects or tasks.

7.Target depends are not mandatory.

8.To print any thing in output on console write it in <echo> and </echo> tags.

9.All task has to be in a target.


You may also like:-

Using JConsole in java And creating memory dump by it

Heap analysis by Memory Analyzer (MAT) - Eclipse java

Main causes of Out-Of-Memory Errors in java

Five main types of Memory leaks in java

How to Reduce Garbage-Collection Pause Time?

4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?
http://www.casino-online.us

Popular posts from this blog

What are Java heap Young, Old and Permanent Generations?

The Java heap is dived into two parts i.e. Young generation and old generation. Young generationYoung generation  memory is 40% of Maximum Java Heap. It consists of two parts, Eden space and Survivor Space. Eden SpaceInitially objects are created in this  Part of Java Heap , here most objects die and quickly are cleaned up by the minor Garbage Collectors (It only runs in young generation and its frequency is high in compared to major garbage collector). Usually any new objects created inside a Java Method go into Eden space and the objects space is reclaimed once the method execution completes. Whereas the Instance Variables of a Class usually lives longer until the Object based on that class gets destroyed. When Eden fills up it causes a minor collection, in which some surviving objects are moved to Survivor Space or an older generation. Survivor Space  The pool containing objects that have survived the garbage collection of the Eden space The parameter Survivor Ratio can be used to tune…

Compression of HttpServletRequest and HttpServletResponse by gzip encoding

Description 
This filter is on HTTP headers in a HttpServletRequest, compress data written to the HttpServletResponse, or decompress data read from the request. When supported by the client browser, this can potentially greatly reduce the number of bytes written across the network from and to the client. As a Filter, this class can also be easily added to any J2EE 1.3+ web application.





Installation

1).Add the pjl-comp-filter-XX.jar file containing CompressingFilter to your web application's WEB-INF/lib directory.

2).Add the following entries to your web.xml deployment descriptor:

 <filter>
  <filter-name>CompressingFilter</filter-name>
  <filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>CompressingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

The below data is of my application where i tested this compression technique…

4 mains causes of Long Garbage Collection Pause?

So a long GC Pause can have a direct impact on response time and throughput. But there are some causes for long GC pause which you can check and avoid to increase performance. They are as follows:-


1)Insufficient heap size:- If heap size is small then the size required then the allocation requests for new objects  fail and the JVM needs to invoke garbage collections in an attempt to reclaim space for the allocations. So these frequent Full GCs cause long pauses in the application run. To avoid long GC pause by this identify the average footprint of the application and then specify the heap size accordingly.
2)Fragmentation in the heap:-GCs can occur more frequently due to fragmentation in the Java Heap  and also sometimes causing long pauses in the GCs. This is more probable in the case of Concurrent Mark Sweep collector, also known as CMS, where the tenured generation space is not compacted with the concurrent collections. For more please go through the previous post about heap  compact…