background preloader

Ant

Facebook Twitter

Java Software Automation with Jakarta Ant. Java Software Automation with Jakarta Ant Pages: 1, 2, 3 Practical Example Imagine that you need to do some automation in your Web application, say, in a servlet. You can find the complete source code in the references section. Servlets are multithreaded applications, so we need to create a separate temporary directory for each customer. We're going to use session id for that. Because of the servlet specifics, we will need to implement our own BuildListener and InputHandler.

The first class is the HtmlReportLogger, which will use a PrintWriter from the HttpServletRequest to prepare an HTML page with the build results to return to the Web browser. project.addBuildListener( new HtmlReportLogger( res.getWriter())); The second class is the ServletLogger, which utilizes the ServletContext logging facilities to write the report to the application server log. project.addBuildListener( new ServletLogger( this)); yWorks Ant Explorer 1.0.2 - This application visualizes Ant Build files. Technology... Innovation... Automation. ANT as a automation tool When it come to build automations, ANT is one of the most powerful tool that can be used. There might be other tools too, but ANT is most widely available and usable.

If you are new to ANT then visit If you want to explore the power of ANT then visit write or use ANT first you will have to install it. To find out from where to download and how to isntall ANT please visit Here I will take an process as an example and we'll see how we can automate the process using ANT and make our life easier. Consider the following process:You have some bunch of programmers working on a project and you are using a central repository; CVS or VSS.

As you can see, the steps mentioned above are atomic tasks that needs to be performed. We will define each step or set of steps as a target. 1. If you are using VSS, ANT provides optional task for the same. 2. 5. Running Apache Ant. Command Line If you've installed Apache 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 <project> tag. To make Ant use a build file other than build.xml, use the command-line option , where file is the name of the build file you want to use (or a directory containing a build.xml file). If you use the 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. You can also set properties on the command line. Command-line Options Summary Library Directories ant. Overview of Apache Ant Tasks. Evil Ant Build Properties. By Paul Wheaton The Problem (and intermediate solutions) I have worked on no less than five projects where the standard, when I arrived, was to have a build.properties file right next to the build.xml file.

Both go into version control. What always happens is that somebody changes a property to make the build work on their system. Then they check in their changes and everybody else's build breaks. The most common first solution is to simply not check in that file. This works kinda-okay until somebody accidentally checks it in. The next solution is to put build.properties into your home directory and have ant find it there. The next improvement is to make a conf directory within the project that is in version control.

Some Desired Goals A) Have as few properties defined outside of build.xml as possible. I have seen projects that have hundreds of build properties defined. The focus of this article is properties that change from developer to developer. A Hybrid Solution [Bonus Trick!] Ant in Anger. Using Apache Ant in a Production Development System Steve Loughran Last updated 2005-03-16 Introduction Apache Ant can be an invaluable tool in a team development process - or it can be yet another source of problems in that ongoing crises we call development . This document contains some strategies and tactics for making the most of Ant. It is moderately frivolous in places, and lacks almost any actual examples of Ant XML. The lack of examples is entirely deliberate - it keeps document maintenance costs down.

Most of the concepts covered don't need the detail provided by XML representations, as it is the processes we are concerned about, not the syntax. Firstly, here are some assumptions about the projects which this document covers: Pretty much pure Java, maybe with some legacy cruft on the edges. Core Practices Clarify what you want Ant to do Ant is not a silver bullet. Define standard targets When you have multiple sub projects, define a standard set of targets. Embrace Automated Testing. TheElementsOfAntStyle - Ant Wiki. The original version of this document was created by Steve Loughran and Erik Hatcher for Java Development with Ant. It was used by permission (verified with the author ErikHatcher) AndrewCOliver General principles Let Ant be Ant. Don't try to make Ant into Make. (submitted by Rich Steele, eTrack Solutions, Inc.)

Design for componentization. A small project becomes a large project over time; splitting up a single build into child projects with their own builds will eventually happen. Use <property location> to assign locations to properties, rather than values. Design for maintenance. Will your build file be readable when you get back to it six months after the project is finished? Document the build process. Never neglect false positive test case failures. Environment conventions The items in this section assume that you are launching Ant through the wrapper scripts, such as the provided ant.bat, ant.sh, antrun.pl, or antrun.py.

Run without a classpath. Use ANT_OPTS to control Ant? <? <? General. ANT Tutorial. This section intends to provide and describe a typical Ant buildfile, such that, the example given could be easily modified to suit ones personal needs. When starting a project it is a good idea to follow the suggestion in the Ant documentation of using three directories: Create a test directory and from within this, create the three directories described above. A simple Java program will be used to illustrate the use of Ant. Copy the following program into a file called UKLights.java and place it in the src directory: Alternatively, download the file from here: UKLights.java. Readers of the print version of this tutorial should use some other jpeg or gif and make the necessary adjustments to the program source. The program displays the specified image in a JFrame. The first thing that the build file must contain is a standard XML declaration: This provides a way for any tools that may process the file to find out the version of XML in use.

This target has a name and a description.