Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Next, we’ll have to build the Groovy module. This can easily be done by using the groovyc compiler and packaging the code into a bundle, just like we did when building the Java version of the calculator. First, we must ensure that the Groovy library is on our build classpath. Then, we’ll define an Ant task for the compilation step. Listing 16.6 illustrates the snippets of the build file that perform these tasks for us. Once the code is compiled, it can be packaged into a bundle using the same mechanisms as the Java code.
Listing 16.6. Groovy Calculator Build Script
<path id="groovy.class.path">
<pathelement path="${groovy.library.jar}"/>
<pathelement path=
"${groovy.dir}/lib/commons-cli-1.2.jar"/>
<pathelement path="${groovy.dir}/lib/asm-3.2.jar"/>
<pathelement path="${groovy.dir}/lib/antlr-2.7.7.jar"/>
</path>
<taskdef name="groovyc"
classname="org.codehaus.groovy.ant.Groovyc"
classpathref="groovy.class.path"/>
<target name="compile" depends="init">
<groovyc srcdir="${groovy.src}"
destdir="${groovy.build}">
<classpath refid="project.class.path"/>
</groovyc>
</target>