In one of my recent projects i had to integrate Groovy with JSF 2.0 in Netbeans 6.8. I don’t speak of using groovy as managed bean code or JSF renderer, etc. I just want to use some groovy classes to help me with sending mail or parsing xml and so on.
It turned out to be a little tricky as everything compiled well during programming but if i tried to run the project the glassfish server complained about missing implementation of an abstract method. The key point is groov’s joint compilation. If you run a netbeans project it executes an ant build.xml file which can be found in the root project folder. This file is pretty empty as it imports the main compile and deploy tasks from another ant file in the “nbproject” folder.
Now you can customize the build.xml file to enable joint compilation. For this you have to modify the build.xml file in this way:
1. Insert this after the import tag:
<taskdef name=”groovyc” classname=”org.codehaus.groovy.ant.Groovyc” />
2. Copy the target “-init-macrodef-javac” from the nbproject/build-impl.xml file to the end of the build.xml file. You have to modify the target like:
<target name=”-init-macrodef-javac”>
<macrodef name=”javac” uri=”http://www.netbeans.org/ns/web-project/2“>
<attribute default=”${src.dir}” name=”srcdir”/>
<attribute default=”${build.classes.dir}” name=”destdir”/>
<attribute default=”${javac.classpath}:${j2ee.platform.classpath}” name=”classpath”/>
<attribute default=”${includes}” name=”includes”/>
<attribute default=”${excludes}” name=”excludes”/>
<attribute default=”${javac.debug}” name=”debug”/>
<attribute default=”${empty.dir}” name=”gensrcdir”/>
<element name=”customize” optional=”true”/>
<sequential>
<property location=”${build.dir}/empty” name=”empty.dir”/>
<mkdir dir=”${empty.dir}”/>
<groovyc destdir=”@{destdir}” encoding=”${source.encoding}” excludes=”@{excludes}” includeantruntime=”false” includes=”@{includes}” srcdir=”@{srcdir}” >
<src>
<dirset dir=”@{gensrcdir}” erroronmissingdir=”false”>
<include name=”*”/>
</dirset>
</src>
<classpath>
<path path=”@{classpath}”/>
</classpath>
<javac source=”${javac.source}” target=”${javac.target}” debug=”on” deprecation=”${javac.deprecation}”>
<compilerarg line=”${endorsed.classpath.cmd.line.arg}”/>
<compilerarg line=”${javac.compilerargs}”/>
<customize/>
</javac>
</groovyc>
</sequential>
</macrodef>
</target>
Look how we integrated the groovyc compiler which first compiles the groovy sources and afterwards the java sources with nested <javac>
3. You should extend the nbproject/project.properties with: build.classes.excludes=**/*.java,**/*.form,**/*.groovy
Otherwise groovy source files will be deployed along with the class files.
Now you can run your project from netbeans 6.8 with the RUN button.
Have fun!






Hi, thanks for this soution, but not worked for me… I got an error when I try to “clean & build” in netbenas 6.8, Thanks.