What is ant?
ANT is a Java based building tool, which is similar to make(Unix).
What is the use of Ant?
*Ant is a build tool that is java based
*Placing this byte code in a package
*Deployment to production systems
*Document creation and release notes preparation.
*Supports Cross Platform Java Development
*Each command is executed from within JVM
*Tools like javac are new threads – not new process
*Ant's Debug Options are very helpful
*Supports Cross Platform Java Development
*XML much easier to read than MAKEFILE
how to start to use Ant and provide a "Hello World" ant script.
Download the most recent version of ant from Apache; unzip it some where on your machine.Install j2sdk 1.4 or above.
Before start using ant, we should be clear about the project name and the .java files and most importantly, the path where the .class files are to be placed.
For example, we want the application HelloWorld to be used with ant. The Java source files are in a subdirectory called Dirhelloworld, and the .class files are to put into a sub directory called Helloworldclassfiles.
1. The build file by name build.xml is to be written. The script is as follows
2. Now run the ant script to perform the compilation:
C :\> ant
Buildfile: build.xml
and see the results in the extra files and directory created:
c:\>dir Dirhelloworld
c:\>dir Helloworldclassfiles
All the .java files are in Dirhelloworld directory and all the corresponding .class are in Helloworldclassfiles directory.
Note: mkdir command is to be used in MS-DOS and mk dir command is to be used in UNIX/Linux
Dir command is to be used in MS-DOS and ls command is to be used in UNIX /Linux
Where can I find the javadoc for ant API?
Download apache ant src version. Use ant javadocs command to see generated javadoc for ant in build/docs directory.
How do I debug my ant script?
* Do an echo on where you have doubt. You will find out what is the problem easily. Just like the old c printf() or Java System.println()
* Use project.log("msg") in your javascript or custom ant task
* Run Ant with -verbose, or even -debug, to get more information on what it is doing, and where. However, you might be tired with that pretty soon, since it give you too much information.
There are many ways to solve the problem.
Since target if/unless all depend on some property is defined or not, you can use condition to define different NEW properties, which in turn depends on your ant property values. This makes your ant script very flexible, but a little hard to read.
* Ant-contrib has <if> <switch> tasks
for you to use.
* Ant-contrib also has <propertyregex> which
can make very complicate decisions.
What are the tasks can be perform using ANT?
* Archive Tasks (Jar, Ear, Tar, War, GZip, Zip 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.)
* Logging Tasks (Record)
* Mail Tasks (Mail, MimeMail)
* Miscellaneous Tasks (Echo, GenKey, Script, Sql etc.)
* .NET Tasks
* Remote Tasks (FTP, Telnet etc. )
* SCM Tasks (Cvs, CvsChangeLog, CVSPass etc.)
* Testing Tasks (Junit, JunitReport, Test)
LOG4J
What is log4j?
log4j is a tool to help the programmer output log statements to a variety of output targets.
Logging is very important for tracing and knowing how system is working in deployment/production environment. In case of any defects logged by customer/end user, one of the initial way to find out the problem, where it occurred is by
analysing log file.
Logging within the context of program development constitutes inserting statements into the program that provide some kind of output information that is useful to the developer. Inserting log statements into your code is a general method for debugging it. Examples of logging are trace statements, dumping of structures and the familiar System.out.println or printf debug statements
With log4j it is possible to enable logging at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost. Logging behavior can be controlled by editing a configuration file, without touching the application binary.
With log4j it is possible to enable logging at runtime without modifying the application binary. The log4j package is designed so that these statements can remain in shipped code without incurring a heavy performance cost. Logging behavior can be controlled by editing a configuration file, without touching the application binary.
Advantage of using Log4J?
• Logging behavior can be set at runtime using a configuration file. Configuration files can
be property files or in XML format.
• log4j is designed to handle Java Exceptions from the start.
• log4j can direct its output to a file, the console, a java.io.OutputStream, java.io.Writer, a
remote server using TCP, a remote Unix Syslog daemon, to a remote listener using JMS,
to the NT EventLog or even send e-mail.
• The format of the log output can be easily changed by extending the Layout class. The
target of the log output as well as the writing strategy can be altered by implementations
of the Appender interface.
• log4j supports multiple output appenders per logger.
• It supports hierarchical logging. It is possible to select (at runtime) which log statements
are output at arbitrary granularity. Users can choose to implement their own log formats
and output strategies.
From where to get log4j?
Download the log4j distribution from http://jakarta.apache.org/log4j/docs/download.html.
What are the other logging frameworks are available?
• Jlog
• JavaTM Logging
• Protomatter
• Message LFW
wow cool site for learning java related stuff.....
ReplyDeleteThanks Praveen :)
ReplyDelete