how is this

PDF Generation with Big Faceless Report Generator

Big Faceless Report Generator is a commercial Java API for generating PDF files from XML input. The report generator is built on the Big Faceless Java PDF library. It has a very easy to use API, but the one thing that I like most about it is, for it is more than a bargain for the price you pay for it. It easily out performs the open source PDF generators (iText and XSL FOP) and also has a lot of intersting features.
  • HTML-style Tables - auto-sized nested tables with full control over padding, margins and borders
  • Support for CSS2 Style sheets
  • Create inline graphs and charts with XML, direct from the database
  • Includes a servlet and a servlet filter for simple generation of PDF's from XML or JSP pages.
  • Auto pagination of content with page headers and footers
  • Familiar HTML syntax - <a>, <ul>, <p>, <table>, <td> and so on - simpler and faster than FOP
  • Unicode support, Encryption, TrueType fonts, Barcodes and more
  • Load existing PDF documents as templates
  • Digitally sign documents
  • Create and edit interactive Forms, or "AcroForms"
The following is an example of how to use the Report generation library to create PDF files using an XML for input Data, and an XSL as a template. Follow these steps to implement the example
  1. Download Big Faceless Report generator from here. You only have to include the bforeport.jar file in your classpath.
  2. Create the input XML file as shown below:
    <?xml version="1.0" encoding="UTF-8"?> <Org> <Employee>
  3. <firstName>Asif</firstName>
  4. <lastName>Mandvi</lastName>
  5. <dateOfBirth>1/1/1900</dateOfBirth>
  6.  </Employee>
  7. <Employee>
  8.  <firstName>James</firstName>
  9. <lastName>Baker</lastName>
  10. <dateOfBirth>1/1/1900</dateOfBirth>
  11.  </Employee> <Employee>
  12. <firstName>Jon</firstName>
  13. <lastName>Stewart</lastName>
  14. <dateOfBirth>1/1/1900</dateOfBirth>
  15. </Employee> <Employee>
  16. <firstName>Stephen</firstName>
  17. <lastName>Colbert</lastName>
  18. <dateOfBirth>1/1/1900</dateOfBirth>
  19. </Employee> <Employee>
  20. <firstName>Samantha</firstName>
  21. <lastName>Bee</lastName>
  22.  <dateOfBirth>1/1/1900</dateOfBirth>
  23. </Employee> <Employee>
  24. <firstName>Jon</firstName>
  25.  <lastName>Oliver</lastName>
  26. <dateOfBirth>1/1/1900</dateOfBirth>
  27. </Employee>
  28. </Org>
    test.xml
  29. Create the template for the PDF(XSL) as shown below.
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  30.  <xsl:output indent="yes" /> <xsl:preserve-space elements="true" />
  31.  <xsl:template match="Org"> <pdf>  <body>
  32.  <table font-size="12pt" width="700px">
  33.  <tr font-weight="bold">
  34.  <td>First Name</td>
  35.  <td>Last Name</td>
  36.  <td>Date of Birth</td>
  37.  </tr>
  38.  <xsl:for-each select="/Org/Employee">
  39.  <tr>
  40.  <td>
  41.  <xsl:value-of select="firstName" />
  42.  </td>
  43.  <td>
  44.  <xsl:value-of select="lastName" />
  45.  </td>
  46.  <td>
  47.  <xsl:value-of select="dateOfBirth" />
  48.  </td>
  49.  </tr>
  50.  </xsl:for-each>
  51.  </table>
  52. </body> </pdf> </xsl:template> </xsl:stylesheet>
    test.xsl
    This XSL file will be used to create the final XML file that will sent as input to the Report generator.
  53. Transform the XML to the format required by the report generator: The XML file cannot be used as input to the report generator directly. It has to be first transformed into the required format. That is reason for using the XSL.
    public class ConvertXML {
  54. public void renderReport() {
  55. try {
  56. TransformerFactory factory = TransformerFactory.newInstance();
  57.  StreamSource stylesheet = new StreamSource(new FileInputStream("c:\\pdf\\test.xsl"));
  58.  Transformer transformer = factory.newTransformer(stylesheet);
  59.  Source src = new StreamSource(new FileInputStream("c:\\pdf\\test.xml"));
  60.  Result res = new StreamResult(new FileOutputStream("c:\\pdf\\intermediate.xml"));
  61.  transformer.transform(src, res);
  62. } catch (Exception e) {
  63.  e.printStackTrace();
  64.  }
  65.  }
  66.  }
    ConvertXML.java
  67. The following code can be used to generate the final PDF: The PDFGenerator first uses the ConvertXML to transform the input to the report generator input format (intermediate.xml), and then invokes the report generator.
    public class PDFGenerator {
  68. public void createPDF(String xmlfile, OutputStream out) {
  69. ReportParser parser;
  70.  try {
  71.  parser = ReportParser.getInstance();
  72. InputSource src = new InputSource(new FileInputStream(xmlfile));
  73.  PDF pdf = (PDF) parser.parse(src);
  74.  pdf.render(out);
  75. out.close();
  76. } catch (Exception e) {
  77.  e.printStackTrace();
  78.  }
  79. }
  80.  public static void main(String args[]) {
  81. PDFGenerator gen = new PDFGenerator();
  82. OutputStream os = null;
  83. try {
  84. ConvertXML cx = new ConvertXML();
  85. cx.renderReport();
  86.  os = new FileOutputStream("c:\\pdf\\test.pdf");
  87. } catch (FileNotFoundException e) {
  88.  e.printStackTrace();
  89.  }
  90. gen.createPDF("C:\\pdf\\intermediate.xml", os);
  91.  }
  92.  }

  93. PDFGenerator.java

WHAT HAPPENS IN HEAVEN !!.

WHAT HAPPENS IN HEAVEN

This is one of
the nicest e-mails I have seen and is so true:

I dreamt that I went to Heaven and an angel was showing me around.
We walked side-by-side inside a large workroom filled with
angels.

My angel guide stopped in front of the first section and said, 'This Is the Receiving Section. Here, all petitions to God said in prayer are Received.'

I looked around in this area, and it was terribly busy with so many angels sorting out petitions written on
voluminous paper sheets and scraps from people all over the world.

Then we moved on down a long corridor until we reached the second section.

The angel then said to me, 'This is the Packaging and Delivery Section. Here, the graces and blessings the
people asked for are processed and delivered to the living persons who asked for them.'


I noticed again how busy it was there. There were many angels working hard at that station, since so many
blessings had been requested and were being
packaged for delivery to Earth

Finally at the farthest end of the long corridor we stopped at the Door of a very small station To my great surprise, only one angel was Seated there, idly doing nothing. 'This is the Acknowledgment Section,' My angel friend quietly admitted to me. He seemed embarrassed 'How Is it that there
is no work going on here?' I asked.

'So sad,' the angel sighed. 'After people
receive the blessings that they asked For, very few send back acknowledgments
.'

'How does one acknowledge God's blessings?' I asked.

'Simple,' the angel answered. Just say, 'Thank you, Lord.'


'What blessings should they acknowledge?' I asked.


'If you have food in the refrigerator, clothes on your back, a roof overhead and a place to sleep you are richer than 75% of this world.
If you have money in the bank, in your wallet, and spare change in a dish, you are among the top 8% of the world's wealthy .'

'And if you get this on your own computer, you are part of the 1% in the world who has that opportunity.'

Also ......

'
If you woke up this morning with more health than illness ... You are more blessed than the many who will not even survive this day .'

'If you have never experienced the fear in battle, the loneliness of imprisonment, the agony of torture, or
the pangs of starvation .. You are ahead of 700 million people in the world.'

'If you can attend a ceremony without the fear of harassment, arrest, torture or death you are envied by, and more blessed than, three billion people
In the world
'

'If your parents are still alive and still
married
...you are very rare .'

'If you can hold your head up and smile, you are not the norm, you're unique to all those in doubt and despair.'


Ok, what now?
How can I start?

If you can read this message, you just received a double blessing in that someone was thinking of you as very special and you are more blessed than over two billion people in the world who cannot read at all.


Have a good day, count your blessings, and if you want, pass this along to remind everyone else how blessed we all are.

A
TTN:
Acknowledge Dept.:
'Thank you Lord, for giving me the ability to share this message and for giving me so many wonderful people to share it
with.

Document convertion

import com.sun.star.bridge.XUnoUrlResolver;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;





/** The class DocumentConverter allows you to convert all documents in
* a given directory and in its subdirectories to a given type. A converted
* document will be created in the same directory as the origin document.
*
*/
public class DirectoryPdf {
/** Containing the loaded documents
*/
static XComponentLoader xcomponentloader1 = null;
/** Containing the given type to convert to
*/
// static String stringConvertType = "PDF - Portable Document Format";
static String stringConvertType = "writer_pdf_Export";
/** Containing the given extension
*/
static String stringExtension = "pdf";
/** Containing the current file or directory
*/
static String indent = "";
private static Object xcomponentloader;

/** Traversing the given directory recursively and converting their files to the
* favoured type if possible
* @param fileDirectory Containing the directory
*/
static void traverse( File fileDirectory ) {
// Testing, if the file is a directory, and if so, it throws an exception
if ( !fileDirectory.isDirectory() ) {
throw new IllegalArgumentException(
"not a directory: " + fileDirectory.getName()
);
}

System.out.println(indent + "[" + fileDirectory.getName() + "]");
indent += " ";

// Getting all files and directories in the current directory
File[] entries = fileDirectory.listFiles(
new FileFilter() {
public boolean accept( File pathname ) {
return pathname.getName().endsWith("doc");
}
}
);

// Iterating for each file and directory
for ( int i = 0; i < entries.length; ++i ) {
// Testing, if the entry in the list is a directory
if ( entries[ i ].isDirectory() ) {
// Recursive call for the new directory
traverse( entries[ i ] );
} else {
// Converting the document to the favoured type
try {
// Composing the URL by replacing all backslashs
String stringUrl = "file:///"
+ entries[ i ].getAbsolutePath().replace( '\\', '/' );
System.out.println(entries[i] + ":" + stringUrl);
// Loading the wanted document
Object objectDocumentToStore =
((XComponentLoader) PDFConverter.getXcomponentloader()).loadComponentFromURL(
stringUrl, "_blank", 0, new PropertyValue[0] );

// Getting an object that will offer a simple way to store a document to a URL.
XStorable xstorable =
( XStorable ) UnoRuntime.queryInterface( XStorable.class,
objectDocumentToStore );

// Preparing properties for converting the document
PropertyValue propertyvalue[] = new PropertyValue[ 2 ];
// Setting the flag for overwriting
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "FilterName";
propertyvalue[0].Value = "writer_pdf_Export";

// Setting the filter name
propertyvalue[ 1 ] = new PropertyValue();
propertyvalue[ 1 ].Name = "FilterName";
propertyvalue[ 1 ].Value = PDFConverter.stringConvertType;

//new modification here
propertyvalue[1] = new PropertyValue();
propertyvalue[1].Name = "CompressionMode";
propertyvalue[1].Value = "1";


// Appending the favoured extension to the origin document name
int index = stringUrl.lastIndexOf(".");
stringUrl = stringUrl.substring(0, index + 1) + PDFConverter.stringExtension;

// Storing and converting the document
System.out.println(stringUrl + ":" + propertyvalue);
xstorable.storeToURL( stringUrl, propertyvalue );

// Getting the method dispose() for closing the document
XComponent xcomponent =
( XComponent ) UnoRuntime.queryInterface( XComponent.class,
xstorable );

// Closing the converted document
xcomponent.dispose();
}
catch( Exception exception ) {
exception.printStackTrace();
}

System.out.println(indent + entries[ i ].getName());
}
}

indent = indent.substring(2);
}

/** Connecting to the office with the component UnoUrlResolver and calling the
* static method traverse
* @param args The array of the type String contains the directory, in which all files should be
* converted, the favoured converting type and the wanted extension
*/
public static void main( String args[] ) {
try {

XComponentContext xComponentContext =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );

/* Gets the service manager instance to be used (or null). This method has
been added for convenience, because the service manager is a often used
object. */
XMultiComponentFactory xMultiComponentFactory =
xComponentContext.getServiceManager();


/* Creates an instance of the component UnoUrlResolver which
supports the services specified by the factory. */
Object objectUrlResolver = xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", xComponentContext );

// Create a new url resolver
XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
UnoRuntime.queryInterface( XUnoUrlResolver.class,
objectUrlResolver );

// Resolves an object that is specified as follow:
// uno:;;
Object objectInitial = xurlresolver.resolve( "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" );

// Create a service manager from the initial object
xMultiComponentFactory = ( XMultiComponentFactory )
UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );

// Query for the XPropertySet interface.
XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class, xMultiComponentFactory );

// Get the default context from the office server.
Object objectDefaultContext =
xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" );

// Query for the interface XComponentContext.
xComponentContext = ( XComponentContext ) UnoRuntime.queryInterface(
XComponentContext.class, objectDefaultContext );

/* A desktop environment contains tasks with one or more
frames in which components can be loaded. Desktop is the
environment for components which can instanciate within
frames. */
xcomponentloader = ( XComponentLoader )
UnoRuntime.queryInterface( XComponentLoader.class,
xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.frame.Desktop", xComponentContext ) );

// Getting the given starting directory
File file = new File("/home/anilgoud/Desktop/test");

// Getting the given type to convert to
//stringConvertType = "MS Word 97";
stringConvertType = "writer_pdf_Export";

// Getting the given extension that should be appended to the origin document
// stringExtension = "doc";
stringExtension = "pdf";
// Starting the conversion of documents in the given directory and subdirectories
traverse( file );

System.exit(0);
}
catch( Exception e ) {
e.printStackTrace();
}
}
}

Truth saying Robot (Mindblowing!!!!!!)

One day Kuttappan's dad bought a robot.

The robot was special in that it could detect a lie and would slap the person who lied on the face.

Kuttappan returned late from school that day and his dad asked him, "Son why are you late from school?".

Kuttappan answered, "Dad we had extra classes today".

Much to his astonishment the Robot jumped up and

slapped

Kuttappan on his face.

His dad told him "Mone (son), This robot is special in that he can detect a lie and will then slap the person who lied now come on tell me the truth, Why are you late?"

"Dad I went for a movie", " Which movie?" "The Ten Commandments",

Splatt

Kuttappan got a tight slap on the face from the robot.

"No dad honest I went for the movie Sex Queen."

Dad :"Shame on you son when I was your age I never used to do such shameful things."

Splatt

, the dad gets a tight slap on the face from the robot.

Hearing all this, Kuttappans mother comes walking out of the kitchen saying,

"After all he is your son.......", to which the robot steps up and gives a resounding slap on Kuttappan's mother's face.

A touching story

I was walking around in a BigBazar store making shopping, when I saw a Cashier talking to a boy couldn't have been more than 5 or 6 years old.

The Cashier said, 'I'm sorry, but you don't have enough money to buy

this doll. Then the little boy turned to me and asked: ''aunty, are you sure I don't have enough money?''

I counted his cash and replied: ''You know that you don't have enough money to buy the dolll, my dear.'' The little boy was still holding the doll in his hand.

Finally, I walked toward him and I asked him who he wished to give this

doll to. 'It's the doll that my sister loved most and wanted so much . Iwanted to Gift her for her BIRTHDAY.

I have to give the doll to my mommy so that she can give it

to my sister when she goes there.' His eyes were so sad while saying this. 'My Sister has gone to be with God. Daddy says that Mommy is going to see God very soon too, so I thought that she could take the doll with her to give it to my sister.''

My heart nearly stopped. The little boy looked up at me and said: 'I told daddy to tell mommy not to go yet. I need her to wait until I come back from the mall.' Then he showed me a very nice photo of him where he was laughing. He then told me 'I want mommy to take my picture with her so my sister won't forget me.' 'I love my mommy and I wish she doesn't have to leave me, but daddy says that she has to go to be with my little sister.' Then he looked again at the doll with sad eyes, very quietly.

I quickly reached for my wallet and said to the boy. 'Suppose we check

again, just in case you do have enough money for the doll?''

'OK' he said, 'I hope I do have enough.' I added some of my money to his with out him seeing and we started to count it. There was enough for the doll and even some spare money.

The little boy said: 'Thank you God for giving me enough money!'

Then he looked at me and added, 'I asked last night before I went to

sleep for God to make sure I had enough money to buy this doll, so that

mommy could give It to my sister. He heard me!'' 'I also wanted to have enough money to buy a white rose for my mommy,

but I didn't dare to ask God for too much. But He gave me enough to buy the doll and a white rose. My mommy loves white roses.'

I finished my shopping in a totally different state from when I started. I

couldn't get the little boy out of my mind. Then I remembered a local

news paper article two days ago, which mentioned a drunk man in a truck, who hit a car occupied by a young woman and a little girl. The little girl died right away, and the mother was left in a critical state. The

family had to decide whether to pull the plug on the life-sustaining

machine, because the young woman would not be able to recover from the coma. Was this the family of the little boy?

Two days after this encounter with the little boy, I read in the news

paper that the young woman had passed away.. I couldn't stop myself as I bought a bunch of white roses and I went to the funeral home where the body of the young woman was exposed for people to see and make last wishes before her burial. She was there, in her coffin, holding a

beautiful white rose in her hand with the photo of the little boy and

the doll placed over her chest. I left the place, teary-eyed, feeling

that my life had been changed for ever.

The love that the little boy had for his mother and his sister is still,

to this day, hard to imagine. And in a fraction of a second, a drunk

driver had taken all this away from him.

Please DO NOT DRINK & DRIVE.

Now you have 2 choices:

1) Forward this message, or

2) Ignore it as if it never touched your heart.

The value of a man or woman resides in what he or she gives, not in what they are capable of receiving.

Side Effects of Love : Female Version !!!

Overtime -


Food -
as much as he might be OK with you not knowing how to cook, he expects you will learn and make him some good food, if not as good as his moms (never will be), atleast something edible.


Food changes everything -
His mood, his feelings for you, his opinion of you. Believe me, EVERYTHING.


His friends/ your friends –
become 'Our Friends'


'Commitment' –
the word that scares him the most in the English dictionary.


The 2-faced man –
as much as he likes you to be 'western' in your clothing, he would Really prefer the traditional girl in you.


The Kid -
Men will always be boys. They don't grow up..EVER.


Appreciate his brilliance from time to time -
Men like to be appreciated for their ideas/ methods / conversations / advice.. Many of the brilliant conversations come after a few pegs are down.. (they may be repetitive, but, don't notice).. So, give it to him .

Tell him who you find Hot. He doesn't believe in the line, " Tu hi to mera sansar hai.. Aisa mera pyaar hai". He wants to know who his competition is!! (Even though there may be none).


Momma's boy –
At the end, Momma knows everything & you don't know anything.


'The Image" –
'I don't fall for ANY girl.. Girls fall for me" Poor dude, doesn't know when reality hits him, "Chappad phaad ke deta hai".


Most common gene -
"I am emotionally stable & mature" - Yeah, and I am the princess of Narnia.


Decision Maker –
He makes ALL the decisions in the house.. He decides which bank account the money comes out of – urs or mine?


Sports -
"Even if the streets are filled with riots, and there is an Arsenal – Chelsea match, the match is more important.. Don't disturb!" Even if they don't understand the sport, they have to watch it & make comments.


Friends -
Constant comparison as to whether they are 'Joey' or 'Chandler' or 'Ross', and couldn't care less about which of them you are..


The Acid test -
The best Friend.


Weekend –
"Life is a weekend" – it seems that they live from Sunday to Saturday, and thus you work Overtime (refer to point no. 1) during the week.. and you don't even get any extra credit for it.


Gossip Mongrels –
He wants all the gossip on your friends, but, wont accept that its gossip, coz, then, its called 'An update'.


$moking –
Time pass & a good reason to check out the women at office..


Women Effect -
The ex-s, the present, mom, sister, sister-in-law, cousin sister, all the women in his life- His biggest balancing act.


Work-life balance -
He is always the busy one at work.. If by any chance you are busy one day, god help you.


Flirting –
He thinks it's an art, and he knows it! Worst of all, he thinks that's how he got you.


Fights & Makeup –
Goes by the assumption that a kiss or a rose is all that you need to patch up after a fight.. I say, "Be a man",Lets talk.


TV Remote –
What is that?


Statements you hear often from your boyfriend -

"I have to take care of the family" – I am not family."Main hoon na" – That's the problem.



To the men reading this post -
We all know the reality of the situation, so, lets not be justfying anything said here.

To the women reading this post -
Have I left out any important points?


Disclaimer –
This is a collection of thoughts from women with boyfriends & not about anybody in particular. Any coincidence with my friends' behaviors with their girlfriends is purely coincidental.

Ant

Ant

Ant is a Java based build tool, similar to make, but with better support for the cross platform issues involved with developing Java applications. Ant is the build tool of choice for all Java projects at Apache and many other Open Source Java projects. Ant can be configured to compile your java source code files, build your deployment JAR and WAR files, unit-test code and create projects javadoc documentation.

Ant 1.6.0 adds a lot of new features, most prominently support for XML namespaces as well as a new concept of Ant libraries that makes use of namespaces to avoid name clashes of custom tasks.

Advantages of Ant

  • Build IN Java, USING Java, and FOR Java
  • Supports Java Tools (javac, javadoc, etc.)
  • XML Build File is Easier to Build, Read, and Maintain than MAKE file
  • Easier to Extend
  • Supports Cross Platform Java Development
  • Ant is much faster than using MAKE ? Each command is a new process
  • Ant runs within the JVM
  • Each command is executed from within JVM
  • Tools like javac are new threads – not new process
  • Compiling large number of java source files is MUCH,MUCH faster with Ant
  • Ant's Debug Options are very helpful
  • XML much easier to read than MAKEFILE
  • User does not need to know all command line interface options to tools that can be called programmatically
  • Even OS-Specific commands can be setup in 'TaskDefs' and/or included from other sources
Installing Ant

Regardless of platform, downloading Ant is the first step to installing the software. The files can be downloaded to a temporary directory and then uncompressed to any desired directory. After the download step, the process differs depending on whether you've downloaded the binary distribution or the source distribution.
Ant does not provide an installation program; it runs from wherever you choose to copy the files and directories. Lists the directories that ultimately get created under your main Ant directory.

Directories provided with Ant
bin - Batch files, Perl scripts, and shell scripts for running Ant.
docs - Ant documentation.
lib - Libraries required by Ant to run.
src - Source code for Ant. Provided only in the source distribution.


Binary Installation
The term "binary" just means that everything is compiled and packaged into JAR files for easy execution — you don't need to compile Ant from source.
Steps to install Installation of the binary distribution:
1. Unzip (or untar) the distribution to the desired directory.
2. Set the ANT_HOME environment variable to point to to the ant installation directory.
3. Set the JAVA_HOME environment variable to point to the JDK location.
4. Add ANT_HOME/bin to your system's PATH environment variable.

The ant script uses the ANT_HOME and JAVA_HOME environment variables to configure the CLASSPATH used by the JVM running Ant. If these variables are not set, the startup script attempts to infer the correct values, subject to operating system limitations.

Source Installation
Installing the Ant source distribution requires a little more work than installing the binary distribution. As expected, downloading and uncompressing the distribution is the first step.
You generally want to place the source files in a directory separate from any existing Ant installations. Next, ensure that JAVA_HOME points to the JDK distribution. As with the binary installation, you should also set ANT_HOME and update your PATH.
type the following command from the source distribution directory:


build -Ddist.dir=destination_directory dist (Windows)
build.sh -Ddist.dir=destination_directory dist (Unix)

The build script creates a complete binary distribution of Ant in the specified destination directory. When omitted, dist.dir defaults to build.


Ant Basics

Each 'Project' has a Build File, Default build file name is 'build.xml', Can Specify any name with '-buildfile' command line option, Ant's buildfiles are written in XML.

The first or root element of any buildfile is always the tag. No buildfile can be without one nor can it have more than one.


...


The tag has three attributes: name, default, and basedir.

  • The name attribute gives the project a name.
  • The default attribute refers to a target name within the buildfile. If you run Ant without specifying a target on the command line, Ant executes the default target. If the default target doesn't exist, Ant returns an error.
  • The basedir attribute defines the root directory of a project. Typically, it is ".", the directory in which the buildfile resides, regardless of the directory you're in when you run Ant. However, basedir can also define different points of reference.

Each buildfile contains one project and at least one (default) target. Examples are: 'compile', 'test', 'install', 'clean', etc.
...

The tag has three attributes: name, depends, if, unless, descriptiondefault, and basedir.

  • The name attribute gives the target a name.
  • The depends attribute are a comma-separated list of names of targets on which this target depends.
  • The if attribute the name of the property that must be set in order for this target to execute.
  • The unless attribute the name of the property that must not be set in order for this target to execute.
  • The description attribute a short description of this target's function.

Targets must have a name and may have several additional attributes that determine when and if the target actually gets executed. The target is made up of one or more Tasks like invoke a command or another program. Targets can have Dependencies, examples: 'install' depends on 'compile', Targets can handle cascading dependencies, each Dependency is handled only once, dependency executed only if required.

It should be noted, however, that Ant's depends attribute only specifies the order in which targets should be executed - it does not affect whether the target that specifies the dependency(s) gets executed if the dependent target(s) did not (need to) run.

Ant tries to execute the targets in the depends attribute in the order they appear (from left to right). Keep in mind that it is possible that a target can get executed earlier when an earlier target depends on it.A target gets executed only once, even when more than one target depends on it .

A is a piece of code that can be executed.
A task can have multiple attributes (or arguments, if you prefer). The value of an attribute might contain references to a property. These references will be resolved before the task is executed. Tasks have a common structure:

where name is the name of the task, attributeN is the attribute name, and valueN is the value for this attribute.

Each task element of the buildfile can have an id attribute and can later be referred to by the value supplied to this. The value has to be unique. Each Task is bound to a Java class file that Ant executes, passing to it any arguments or sub-elements defined with that task. The Ant tool is extensible and it allows you to create your own tasks

Typical build.xml Tasks
init, sets properties, prepare, creates directories, build, builds the system, package, creates jar file, install, installs an application to Tomcat or other engine, deploy, deploy a WAR engine, reload, update previously installed application engine, redeploy.


Properties

A project can have a set of properties. These might be set in the buildfile by the property task, or might be set outside Ant. A property has a name and a value; the name is case-sensitive. Properties may be used in the value of task attributes. This is done by placing 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. This is resolved at run-time as build/classes.

Built-in Properties
Ant provides access to all system properties as if they had been defined using a task. For example, ${os.name} expands to the name of the operating system. For a list of system properties see the Javadoc of System.getProperties.
In addition, Ant has some built-in properties:

basedir the absolute path of the project's basedir (as set with the basedir attribute of ).
ant.file the absolute path of the buildfile.
ant.version the version of Ant
ant.project.name the name of the project that is currently executing; it is set in the name attribute of .
ant.java.version the JVM version Ant detected; currently it can hold
the values "1.1", "1.2", "1.3" and "1.4".

Using Ant

Ant is a Java based build tool, similar to make, but with better support for the cross platform issues involved with developing Java applications. Ant is the build tool of choice for all Java projects at Apache and many other Open Source Java projects. Ant can be configured to compile your java source code files, build your deployment JAR and WAR files, unit-test code and create projects javadoc documentation.

Ant 1.6.0 adds a lot of new features, most prominently support for XML namespaces as well as a new concept of Ant libraries that makes use of namespaces to avoid name clashes of custom tasks.

Advantages of Ant

  • Build IN Java, USING Java, and FOR Java
  • Supports Java Tools (javac, javadoc, etc.)
  • XML Build File is Easier to Build, Read, and Maintain than MAKE file
  • Easier to Extend
  • Supports Cross Platform Java Development
  • Ant is much faster than using MAKE ? Each command is a new process
  • Ant runs within the JVM
  • Each command is executed from within JVM
  • Tools like javac are new threads – not new process
  • Compiling large number of java source files is MUCH,MUCH faster with Ant
  • Ant's Debug Options are very helpful
  • XML much easier to read than MAKEFILE
  • User does not need to know all command line interface options to tools that can be called programmatically
  • Even OS-Specific commands can be setup in 'TaskDefs' and/or included from other sources
Running Ant

Command Line
If you've installed Ant as described in the Installing Ant section, running Ant from the command-line is simple: just type ant.

When no arguments are specified, Ant looks for a build.xml file in the current directory and, if found, uses that file as the build file and runs the target specified in the default attribute of the tag. To make Ant use a build file other than build.xml, use the command-line option -buildfile file, where file is the name of the build file you want to use

If you use the -find [file] option, Ant will search for a build file first in the current directory, then in the parent directory, and so on, until either a build file is found or the root of the filesystem has been reached. By default, it will look for a build file called build.xml. To have it search for a build file other than build.xml, specify a file argument.

Note: If you include any other flags or arguments on the command line after the -find flag, you must include the file argument for the -find flag, even if the name of the build file you want to find is build.xml.


You can also set properties on the command line. This can be done with the -Dproperty=value option, where property is the name of the property, and value is the value for that property. If you specify a property that is also set in the build file (see the property task), the value specified on the command line will override the value specified in the build file. Defining properties on the command line can also be used to pass in the value of environment variables - just pass -DMYVAR=%MYVAR% (Windows) or -DMYVAR=$MYVAR (Unix) to Ant. You can then access these variables inside your build file as ${MYVAR}. You can also access environment variables using the property task's environment attribute.

Options that affect the amount of logging output by Ant are:
-quiet, which instructs Ant to print less information to the console;
-verbose, which causes Ant to print additional information to the console;
-debug, which causes Ant to print considerably more additional information.
It is also possible to specify one or more targets that should be executed. When omitted, the target that is specified in the default attribute of the project tag is used.
The -projecthelp option prints out a list of the build file's targets. Targets that include a description attribute are listed as "Main targets", those without a description are listed as "Subtargets", then the "Default" target is listed.

Command-line Options Summary
ant [options] [target [target2 [target3] ...]]

Options:

-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to diagnose or report problems.
-quiet, -q be extra quiet
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib specifies a path to search for jars and classes
-logfile use given file for log
-l use given file for log
-logger the class which is to perform logging
-listener add an instance of class as a project listener
-noinput do not allow interactive input
-buildfile use given buildfile
-file use given buildfile
-f use given buildfile
-D= use value for given property
-keep-going, -k execute all targets that do not depend on failed target(s)
-propertyfile load all properties from file with -D properties taking precedence
-inputhandler the class which will handle input requests
-find (s)earch for buildfile towards the root of
-s the filesystem and use it

Ant tasks

The following tables provide a short description of each task.

  • Archive Tasks (Jar, Ear, Tar, War, GZip, Zip etc.)
  • Audit/Coverage Tasks (JDepend, JPorbe, MMetrics, etc. )
  • Compile Tasks (javac, jspc, rmic etc.)
  • Deployment Tasks (ServerDeploy)
  • Documentation Tasks (Javadoc, Stylebook)
  • EJB Tasks
  • Execution Tasks (Ant, Antcall, Exec, Java, Sleep etc.)
  • File Tasks (Attrib, Copy, Copydir, delete, Mkdir etc.)
  • Java2 Extensions Tasks (Jarlib-available, Jarlib-display etc.)
  • Logging Tasks (Record)
  • Mail Tasks (Mail, MimeMail)
  • Miscellaneous Tasks (Echo, GenKey, Script, Sql etc.)
  • .NET Tasks
  • Pre-process Tasks (ANTLR, AntStructure, Import, Xslt/Style etc.)
  • Property Tasks (Available, Basename, BuildNumber, LoadFile etc.)
  • Remote Tasks (FTP, Telnet etc. )
  • SCM Tasks (Cvs, CvsChangeLog, CVSPass etc.)
  • Testing Tasks (Junit, JunitReport, Test)
  • Visual Age for Java Tasks


Core tasks

  • Ant
  • AntCall
  • AntStructure
  • Apply/ExecOn
  • Available
  • Basename
  • BuildNumber
  • BUnzip2
  • BZip2
  • Checksum
  • Chmod
  • Concat
  • Condition
  • Supported conditions
  • Copy
  • Copydir
  • Copyfile
  • Cvs
  • CvsChangeLog
  • CVSPass
  • CvsTagDiff
  • Defaultexcludes
  • Delete
  • Deltree
  • Dependset
  • Dirname
  • Ear
  • Echo
  • Exec
  • Fail
  • Filter
  • FixCRLF
  • GenKey
  • Get
  • GUnzip
  • GZip
  • Import
  • Input
  • Jar
  • Java
  • Javac
  • Javadoc/Javadoc2
  • LoadFile
  • LoadProperties
  • Mail
  • MacroDef
  • Manifest
  • Mkdir
  • Move
  • Parallel
  • Patch
  • PathConvert
  • PreSetDef
  • Property
  • Record
  • Rename
  • Replace
  • Rmic
  • Sequential
  • SignJar
  • Sleep
  • Sql
  • Style
  • Subant
  • Sync
  • Tar
  • Taskdef
  • Tempfile
  • Touch
  • TStamp
  • Typedef
  • Unjar
  • Untar
  • Unwar
  • Unzip
  • Uptodate
  • Waitfor
  • War
  • WhichResource
  • XmlProperty
  • Xslt
  • Zip
Optional tasks

  • .NET Tasks
  • ANTLR
  • Attrib
  • Cab
  • Chgrp
  • Chown
  • Clearcase Tasks
  • Continuus/Synergy Tasks
  • Depend
  • EJB Tasks
  • Echoproperties
  • FTP
  • IContract
  • Image
  • Jarlib-available
  • Jarlib-display
  • Jarlib-manifest
  • Jarlib-resolve
  • JavaCC
  • Javah
  • JspC
  • JDepend
  • JJDoc
  • JJTree
  • Jlink
  • JProbe Coverage
  • JUnit
  • JUnitReport
  • Metamata Metrics
  • Metamata Audit
  • MimeMail
  • MParse
  • Native2Ascii
  • NetRexxC
  • Perforce Tasks
  • PropertyFile
  • Pvcs
  • RenameExtensions
  • ReplaceRegExp
  • RExec
  • Rpm
  • ServerDeploy
  • Setproxy
  • Scp
  • Script
  • Scriptdef
  • Sound
  • SourceOffSite
  • Splash
  • Sshexec
  • Starteam Tasks
  • Stylebook
  • Symlink
  • Telnet
  • Test
  • Translate
  • Visual Age for Java Tasks
  • Microsoft Visual SourceSafe Tasks
  • Weblogic JSP Compiler
  • XmlValidate
Ant command line arguments

Several tasks take arguments that will be passed to another process on the command line. To make it easier to specify arguments that contain space characters, nested arg elements can be used.

value - a single command-line argument; can contain space characters.
file - The name of a file as a single command-line argument; will be replaced with the absolute filename of the file.
path - A string that will be treated as a path-like string as a single command-line argument; you can use ; or : as path separators and Ant will convert it to the platform's local conventions.
pathref - Reference to a path defined elsewhere. Ant will convert it to the platform's local conventions.
line - a space-delimited list of command-line arguments.


It is highly recommended to avoid the line version when possible. Ant will try to split the command line in a way similar to what a (Unix) shell would do, but may create something that is very different from what you expect under some circumstances.

Examples

is a single command-line argument containing a space character.

represents two separate command-line arguments.

is a single command-line argument with the value \dir;\dir2;\dir3 on DOS-based systems and /dir:/dir2:/dir3 on Unix-like systems.


Command-line Options Summary
ant [options] [target [target2 [target3] ...]]


Options:

-help, -h Displays help information describing the Ant command and its options
-projecthelp, -p Print project help information
-version Print the version information and exit
-diagnostics Print information that might be helpful to diagnose or report problems.
-quiet, -q Suppresses most messages not originated by an echo task in the buildfile
-verbose, -v Displays detailed messages for every operation during a build.
-debug, -d Print debugging information
-emacs, -e Produce logging information without adornments
-lib Specifies a path to search for jars and classes
-logfile Use given file for log
-l Use given file for log
-logger Specifies a class to handle Ant logging.
-listener Add an instance of class as a project listener
-noinput Do not allow interactive input
-buildfile Use given buildfile
-file Use given buildfile
-f Use given buildfile
-D= Defines a property name-value pair on the command line.
-keep-going, -k execute all targets that do not depend on failed target(s)
-propertyfile load all properties from file with -D properties taking precedence
-inputhandler the class which will handle input requests
-find Search for buildfile towards the root of the filesystem and use it