Blog Author: Doug Hughes

Doug Hughes is a veteran programmer who founded Alagad after briefly flirting with a career in computer animation. Doug has a strong record of achievement with large, complex web applications. His ability to learn and apply new technologies and techniques has helped Doug become one of the web application development industry’s most highly regarded experts.

Doug’s current focus at Alagad is leading an application development team dedicated to helping organizations improve operational efficiency and performance. This commitment to client success has helped Alagad achieve record growth. A frequent speaker at industry conferences and user groups, Doug also regularly contributes to several well-known open source projects. In addition, his articles have been featured in numerous technical publications.

Categories
Blog Archives
Blog RSS Feed

RSS FeedSubscribe to our RSS feed or Atom feed.

The Alagad Technical Team Blog

Ant4CF Released – Run Build Files Remotely and Interact with ColdFusion Services From Ant Scripts

Published By: Doug Hughes on Jul 6, 2009 at 01:30 PM
Categories: Alagad , Ant

About a year ago I announced and released CFAnt. CFAnt was my first crack at creating tasks for Ant to made deploying ColdFusion applications with Apache Ant very easy. I never got the impression it was widely used outside of Alagad, but we used it internally to deploy essentially all of our applications.

Those of you who did use it are aware that it had some shortcomings. For example, it required that you place CFAnt directly in your application's webroot. Also, it exposed, perhaps, hundreds of poorly documented tasks for managing ColdFusion configuration.

So, while CFAnt worked well for Alagad, I wanted to find a better and easier way to deploy ColdFusion applications using Ant. This spawned the genesis of Ant4CF, which is officially the second release of CFAnt, but with a new name.

Ant4CF fixes a number of confusing issues with CFAnt and makes it really, really simply to remotely execute build files and to interact with services exposed through Ant4CF. These services include a collection of components which proxy the Admin API features.

Ant4CF is made up of three Ant tasks packaged into a JAR file and a collection of CFML files which you can place anywhere on your server. The most common location for these files is under the CFIDE directory.

With those two things in place you can easily create a build script that kicks off another build script remotely on your server. For example, this is a basic build.xml file:

   1: <project name="Local Build Script" default="Build">
   2:     <target name="Build">
   3:         <input message="Please enter CFAdmin password:" addproperty="cfAdminPassword" />
   4:         <taskdef name="configure" classname="com.alagad.ant4cf.Configure" classpath="antlib/ant4cf-java-2.0-SNAPSHOT-jar-with-dependencies.jar" />
   5:         <taskdef name="remoteant" classname="com.alagad.ant4cf.RemoteAnt" classpath="antlib/ant4cf-java-2.0-SNAPSHOT-jar-with-dependencies.jar" />
   6:         <configure ant4cfUrl="http://yourapp.com/CFIDE/ant4cf" adminPassword="${cfAdminPassword}" />
   7:         <remoteant antfile="remoteBuild.xml" properties="cfAdminPassword,dsnPassword,svnUsername,svnPassword" timeout="120" />
   8:     </target>
   9: </project>

This build file essentially gathers the ColdFusion admin password, defines two of the Ant4CF tasks, configures Ant4CF and then remotely runs a build script named remoteBuild.xml.

To expand on that a bit Ant4CF provides three tasks, two of which are shown above: configure and remoteant.

The configure task tells Ant4CF where to find the Ant4CF files on your server and the password used to access the ColdFusion administrator.

The remoteant task is the more interesting of these two as it specifies a specific ant file to upload to the remote server and run. You can specify a set of properties to pass into that file as well. The remoteant task can also keep track of other third party Ant tasks you're using and will upload those JARs to the server.

This means that you can essentially write an Ant script that does whatever you want and use the remoteant task to run it on your server without change.

Ant4CF also provides a service task that looks like this:

   1: <service component="adminapi.801.datasourceProxy" method="setMSSQL" property="result">
   2:     <argument name="name" value="yourapp" />
   3:     <argument name="host" value="10.248.79.47" />
   4:     <argument name="database" value="yourdatabase" />
   5:     <argument name="username" value="dbusername" />
   6:     <argument name="password" value="${dsnPassword}" />
   7:     <argument name="selectmethod" value="direct" />
   8: </service>

The service task is remnient of the cfinvoke tag in ColdFusion. In the case of the service tag you specify a component and a method and pass arguments into it via the argument tag. Any results are returned into the property specified.

By default, Ant4CF comes with a proxy for the ColdFusion Administrator API. This means that you have all of the capabilities of the Admin API built into Ant4CF. The service example above creates or edits a new MSSQL datasource for you.

In my applications a typical build script will export the application from Subversion, change the ColdSpring configuration, export Model-Glue from SNV and ColdSpring from CVS. I then create my datasource, enable and clear the trusted cache and reload the application.

Want to know how I do this? I type "ant" in the command line. The rest is handled for my automatically!

If you're interested in Ant4CF you can download it here: http://alagad.com/go/products-and-projects/ant4cf/ant4cf

Ant4CF is free, open source, and, believe it or not, documented!

3 responses to “Ant4CF Released – Run Build Files Remotely and Interact with ColdFusion Services From Ant Scripts”

@Doug - this looks awesome! Any chance of converting the documentation in the download from a Word docx to a PDF or RTF? Thanks :)

@John - Thanks for the suggestion. I just uploaded a new zip with PDF documentation.

@Doug - thanks! Off to download now... :)

Leave a Reply