Today, I’d like to present another Ant script for Scala development. I promise it’s going to be the last one, but I felt this mini series wouldn’t be complete without it. This script is for developing a Lift application with Scala. I became interested in Lift in the first half of this year, but unfortunately, I wasn’t able to install it when I wanted to give it a try, because of some besetting problems with Maven. Deplorably, the Lift developers have made Maven a requirement for Lift. If you go to the Lift download page, you wont find a Lift package but a Maven package which you must install in order to retrieve Lift from the central repository. Alternatively, you can fetch the latest Lift sources from GitHub, but then you still need Maven to get the examples to work.
Since Maven and I have a difficult relationship, I mentioned this to the Lift community earlier this year. The community seemed quite pleased with Maven, however, and had little interest in supporting alternatives. Hence, I’ve adapted the Ant script from the last article in order to work with Lift and -while we are at it- replaced the Jetty server that is bundled with Lift with Tomcat. I hope this will be useful for people interested in tinkering with Lift who want to avoid the aggravation of having to deal with Maven. As usual, you can download the project sekeleton and Ant build file right here.
I have packaged the Lift 1.0 jars as well as its dependencies (commons-fileupload.jar and log4j.ar), so that you can get the helloworld example to run without additional installation steps. If you plan to use this for your work, you should replace the Lift jars with the most recent versions from GitHub. The Ant script has the same target definitions as the one I presented for general Web development including deploy, undeploy and reload. The Lift dependencies are likewise handled in the same way, as the script uses everything it finds in the WEB-INF/lib directory. Your only responsibility is to put the right jars in there. The main difference consists of a different directory tree structure that reflects the layout of a standard Lift project. This means you won’t have to rearrange things if you move a project from Maven to Ant. In fact all of the Lift examples should run simply by dropping in the sources (I’ve tried this for a few but not all examples). So, here’s the Ant script:
<!-- classpath for unit test build --> <pathid="test.classpath"> <pathrefid="build.classpath"> <pathelementlocation="${scalatest.jar}"> </pathelement>
<!-- definition for the "scalac" and "scaladoc" ant tasks --> <taskdefresource="scala/tools/ant/antlib.xml"> <classpathrefid="scala.classpath"> </classpath>
<!-- definition for the "scalatest" ant task --> <taskdefclassname="org.scalatest.tools.ScalaTestTask" name="scalatest"> <classpathrefid="test.classpath"> </classpath>
<!-- definition for the "reload", "deploy" and "undeploy" Tomcat tasks --> <taskdefclassname="org.apache.catalina.ant.DeployTask" name="deploy"> <classpathpath="${server.home}/lib/catalina-ant.jar"> </classpath> <taskdefclassname="org.apache.catalina.ant.ReloadTask" name="reload"> <classpathpath="${server.home}/lib/catalina-ant.jar"> </classpath> <taskdefclassname="org.apache.catalina.ant.UndeployTask" name="undeploy"> <classpathpath="${server.home}/lib/catalina-ant.jar"> </classpath>
<!-- create a deployable web archive --> <targetdepends="build"description="war"name="war"> <warbasedir="${web.dir}" destfile="${project.dir}/${ant.project.name}.war" webxml="${web.dir}/WEB-INF/web.xml"> </war>
<!-- creates a deployable web archive with all classes packed into a single jar file --> <targetdepends="build"description="packedwar" name="packedwar"> <jarbasedir="${classes.dir}" destfile="${lib.dir}/${ant.project.name}.jar" duplicate="preserve"> <manifest> <sectionname="Program"> <attributename="Title"value="${ant.project.name}"> <attributename="Build"value="${build.number}"> <attributename="Date"value="${TODAY}"> </attribute> </attribute> </attribute> <deletedir="${classes.dir}"> <warbasedir="${web.dir}" destfile="${project.dir}/${ant.project.name}.war" webxml="${web.dir}/WEB-INF/web.xml"> <deletefile="${lib.dir}/${ant.project.name}.jar"> </delete>
<!-- deploy project on Tomcat server --> <targetdepends="war"description="deploy"name="deploy"> <mkdirdir="${webapp.dir}"> <copytodir="${webapp.dir}"> <filesetdir="${web.dir}"> </fileset> <deploylocalwar="${project.dir}/${ant.project.name}.war" password="${server.manager.password}" path="/${ant.project.name}" url="${server.manager.url}" username="${server.manager.username}"> </deploy>
<!-- update and reload project on Tomcat server --> <targetdepends="build"description="reload"name="reload"> <copyfile="${scala-library.jar}"todir="${lib.dir}"> <copytodir="${webapp.dir}"> <filesetdir="${web.dir}"> </fileset> <reloadpassword="${server.manager.password}" path="/${ant.project.name}" url="${server.manager.url}" username="${server.manager.username}"> </reload>
<!-- remove project from Tomcat server --> <targetdepends="init"description="undeploy"name="undeploy"> <undeploypassword="${server.manager.password}" path="/${ant.project.name}" url="${server.manager.url}" username="${server.manager.username}"> </undeploy>