Samstag, Juni 27, 2009

mixing Java and Groovy in Eclipse

As a server back end for Greasemonkey calls I use com.sun.net.httpserver.HttpServer. The work is done inside an implementation of the com.sun.net.httpserver.HttpHandler interface. To write the HttpHandler in Java started to take more time as I was willing to spend. So I thought it is a good idea to try out Groovy.

Installing Groovy and the corresponding Eclipse plugin was no problem. Running the first test script was straight forward also. But compiling a Java and a Groovy class inside the same project didn't work.

Therefore I did a test by hand.

  • set JAVA_HOME and GROOVY_HOME

  • compile the Groovy class inside projects src directory:

    1. groovyc PlayHttpHandler.groovy

    2. javac AjaxHttpHandler.java

    3. javac AjaxHttpServer.java


  • start the server: java -cp /Volumes/Macintosh\ HD/Applications/groovy-1.6.3/embeddable/groovy-all-1.6.3.jar AjaxHttpServer


This worked. So try again in Eclipse.

First step was to clean the project. But it still doesn't work. All classes are build twice. In bin the Groovy class has an unresolved compile problem. To me it looks like the class was build with javac. In bin-groovy the Groovy class is OK. Unfortunately the Groovy class used during run time is the one from bin. Not sure how to fix this.

Keine Kommentare: