Monday, October 31, 2011

Write Nutch Plugin Code in Groovy

In this post, let us look at how we can integrate groovy into nutch code base so that one can write plugin code in groovy.

Below are the steps

1.Edit "src/plugin/myplugin/ivy.xml" of your plugin to include groovy jar. After edit, dependencies section of the file should look like below
<dependencies>
 <dependency org="org.codehaus.groovy" name="groovy-all" rev="1.7.4"/>
</dependencies>


2.Edit "src/plugin/myplugin/plugin.xml" to include groovy jar. Runtime section of the file after edit should look like below
<runtime>
      <library name="my-plugin.jar">
         <export name="*"/>
      </library>
      <library name="groovy-all-1.7.4.jar"/>
   </runtime>


3.Edit "ivy/ivy.xml" to include below in the dependencies section.
<dependency org="org.codehaus.groovy" name="groovy-all" rev="1.7.4"/>


4.Edit "src/plugin/build-plugin.xml" and add the below taskdef
<taskdef name="groovyc"
 classname="org.codehaus.groovy.ant.Groovyc">
    <classpath refid="classpath"/>
  </taskdef>

add the below target
<target name="groovyCompile">
   <echo message="Compiling groovy classes in plugin: ${name}"/>
   <groovyc
     srcdir="${src.dir}"
     includes="**/*.groovy"
     destdir="${build.classes}">
      <classpath refid="classpath"/>
   </groovyc>
  </target>

and modify target named "compile" to depend on "groovyCompile"
change below
<target name="compile" depends="init,deps-jar, resolve-default">

to <target name="compile" depends="init,deps-jar, resolve-default, groovyCompile">
That's it. Now you should be able to add groovy classes to your plugin and used them in java classes. Also, if you are working in eclipse, do not forget to add groovy-all-1.7.4.jar to your classpath.

No comments:

Post a Comment

Followers