Building Mule Apps with Ant

motif

Mule 3 defined a simple, universal structure for Mule ESB applications. It’s a simpler version of war file format, consisting of a zip file with three sorts of entries:

  • At the top level, configuration files and application properties files
  • In the lib directory, jar files
  • In the classes directory, classes and resource files

We also created a maven plugin to build Mule apps. And we haven’t forgotten about the Ant fans in our community. There are two new Ant tasks to make creating and working with Mule applications a snap.

The first task packages up Mule applications. For example:

This creates a mule application in the file named ${app.file}, using the configuration files in the directory src/main/app and the jar file ${app.jar} in the directory ${dir.build}. Note that the lib and config elements are standard Ant filesets, which give you a powerful syntax for selecting exactly the files you want.

The second task deploys applications to a Mule instance:

This installs two Mule applications in two different ways:

  • The order application is installed into the default Mule installation, which is the one pointed to by the Ant property ${dir.mule.home}.
  • The purchase application is specifically installed into the Mule installation at /usr/opt/mule.

The code for these tasks can be found on GitHub, here. You can download it and either use the already built mule-anttasks.jar, or build it yourself with (what else?) Ant. To use the new tasks in your Ant build scripts requires two steps:

  • To make the code available to Ant, add -lib mule-anttasks.jar to your Ant command line.
  • To make the tasks available within a build script,
    add the line as a child of the main <project> element.

To tie it all together, here’s a version of the Mule Echo example’s build.xml file that uses the new tasks:

Using these tasks, you can create and deploy Mule applications in Ant as simply and naturally as you’d create a jar or a war file.


We'd love to hear your opinion on this post


4 Responses to “Building Mule Apps with Ant”

  1. Why does the code not work when compiled with source=”1.6″ instead of 1.5? It compiles fine but when deployed to Mule gives “Bad version number” exception.

  2. Probably because you’re running Mule under Java 1.5, which rejects 1.6 class files with the exception you mention.

    Note that, starting with version 3.2, Mule will only run under Java 1.6, so now is a good time to update your Java installation.

  3. […] wrote a blog over a year ago showing you how to use Ant to package and deploy your Mule Application to your Mule server. With this blog I’d like to show you how we have extended his work so […]

  4. need to know how to build and deploy mule application using ant in to jboss 7

    Appricitae ur quick assitance.