The objective of this article is to introduce the reader to basics of EasyAnt, a new build system based on Apache Ant and Apache Ivy. In the course of this write up, you will be taken through basics of EasyAnt and a simple-and-live example of setting up an EasyAnt web application project as an example only.
Concepts This section will walk you through basic concepts of EasyAnt.
- Phases: An EasyAnt build process is typically split up into multiple phases, similar to Maven. Each phase has a distinct purpose, and functionality. Technically, a phase is very similar to a target. These are the points of difference from a regular target:
- A phase has no body. It does not contain any build logic. It only exposes a hook where you can plugin your additional build logic. A phase will execute at a particular point of time during the build. If you want to add any additional logic at this point, you can assign your target to a phase, and it is guaranteed to execute in the assigned phase.
- However, if there are (which most likely there will always be) multiple targets associated with a particular phase, then the order of execution of these targets is not fixed or guaranteed.
- Build Types: A build type is a defined import of set of build plugins. Each of these plugins defines a set of functionalities in form of targets and hooks them to different build phases. So, when a build type is invoked, it simply invokes the entire set of targets (/phases) sequentially, resulting in the complete build. There are a set of such standard build types that come packaged with EasyAnt. E.g. build-webapp-java. You can also write your own build type.
- Build Plugins: A piece of functionality that can be plugged into or removed from your build. This plugin could actually perform a piece of your regular build, e.g. compile java classes during build of a complete war. Or, do a utility action, e.g. deploy your built web application onto a packaged Jetty server!
A simple EasyAnt project
Prerequisite: You need to set up EASYANT_HOME property. Point it to your EasyAnt path. For Windows users, do: set EASYANT_HOME=path\to\easyant For Unix, export EASYANT_HOME=path/to/easyant
Then add %EASYANT_HOME%/bin to your PATH variable.
Let us try to setup a project that builds to a Web Application Archive, or a WAR. Say, PROJECT_ROOT is the root directory for your project.
module.ivy Your project is expected to have a module.ivy to define the build of your project. This is a regular IVY specification file.
<ivy-module version="2.0"> <info organisation="my.easyant.project" module="my-webapp" status="integration"> <description> <easyant type="org.apache.easyant#build-webapp-java;0.1"> </easyant> </description> </info> <configurations> <conf name="default" visibility="public/> <conf name="test" visibility="private"/> </configurations> <publications> <artifact type="war"/> </publications> </ivy-module>
The above is a standard ivy specification file, other than the easyant tag. The type attribute takes the build type the project wants to use. In our case, we intend to set up a standard WAR build project. The type attribute has a pattern - repository#artifact;version.
The above file is a sufficient instruction to easyant to build a WAR using the current project.
Directory Structure Similar, to Maven, by default, if you are using a standard build type, you need to follow a standard directory structure. This should be as the build type expects to pick different resources to be present in different directories.

In the above directory structure, all your java sources should go into src/main/java directory. Create a DummyMain.java file inside src/java/my/test directory.
All resources that should move into WEB-INF/classes directory should go inside src/main/resources.
Entire src/main/webapp directory moves into the root of the web application WAR. For instance, you may keep WEB-INF directory inside this directory.
The module.ivy file should reside inside ‘testproj' directory.
Any external dependencies of your project should be specified inside your module.ivy file, dependencies section.
Building the Project The project is now ready to be built. You can simply run: easyant. You should see a ‘target' directory created in your project root. The built war will reside inside the target/artifacts directory.
You can go ahead and deploy it in your app-server.
Build Plugins EasyAnt provides plugins that you can selectively choose to use in your project. These provide you convenience functionalities. E.g. Quick WAR deployments in Jetty, Xookie documentation, Coverage tools etc.
In this tutorial, let us quickly take a look over how we may integrate Jetty with our current war.
Let us first include a ‘Hello World' index.htm inside the src/main/webapp directory. These are the contents of our index.htm:
<html> <head></head> <body> <h3>Hello World !!</h3> </body> </html>
Our module.ivy is the repository of all plugins that our project uses. So, we go ahead and include the Jetty plugin in our module.ivy.
<ivy-module version="2.0"> <info organisation="my.easyant.project" module="my-webapp" status="integration"> <description> <easyant type="org.apache.easyant#build-webapp-java;0.1"> <plugin module="org.apache.easyant#jetty-deploy;0.1" as="jetty"/> </easyant> </description> </info> <configurations> <conf name="default" visibility="public/> <conf name="test" visibility="private"/> </configurations> <publications> <artifact type="war"/> </publications> </ivy-module>
The new line is in bold.
The above line instructs easyant to make the jetty-deploy plugin artifact inside the ‘org.apache.easyant' repository, version 0.1, to be available in the current project.
The jetty-deploy module exposes a target called ‘:run' (by convention all public targets in EasyAnt start with a ‘:' and all private targets start with a ‘-‘). Further, this target depends on the package phase of EasyAnt, which means that by the time this target is executed, the WAR would have been created and available for deployment on Jetty.
Because, in the new line added to module.ivy, the jetty-deploy module was added with an ‘alias' jetty, you can run ‘easyant jetty:run' to build and package your web application, and deploy it on jetty. The command launches jetty, and keeps displaying Jetty logs on console. You can now access your web application on browser. Try hitting http://localhost:8080 !
module.ant If you want to add something to the default build types that come packaged with EasyAnt, you can write a module.ant file in your project root. This is called before EasyAnt executes any of its core build scripts.
You can also include any convenience targets you find useful, that are specific to your project and do not come included in EasyAnt.
Conclusion In this article, we talked about basic EasyAnt concepts, and walked you through a simple tutorial to setup a simple EasyAnt project to build a java Web Application. Similar to the webapplication, there are other build types that are ready to build Standard Java projects, Groovy projects, OSGI bundles, Scala projects. Please feel free to share any ideas or feedback with easyant@googlegroups.com. You can visit http://www.easyant.org/doc/ for more information on EasyAnt.
Trackback(0)
Comments 
Write comment
 |