Posts Tagged ‘Eclipse’

Installing Groovy

Either download from the Windows Installer and follow the install wizard. Or download a binary distribution of Groovy and

  • unpack on your local file system, e.g. C:\Groovy\
  • set your GROOVY_HOME environment variable to the directory you unpacked the distribution
  • optionally add GROOVY_HOME/bin to your PATH environment variable

Test your installation by opening the groovy shell (you can type and execute Groovy statements directly: e.g. def name = ‘mh’; println “Hi $name!”), by executing the following in a command shell: groovysh

Or to run the Swing interactive console type: groovyConsole

To run a specific Groovy script type: groovy MyFirstScript.groovy

Installing Groovy Eclipse Plugin

In the Eclipse update manager (in Eclipse select Help->Install New Software) specify the update site appropriate for your Eclipse version:

  • Eclipse Indigo 3.7:
  • Eclipse Helios 3.6:
  • Eclipse Galileo 3.5:

Select ‘Groovy-Eclipse (Required)’. Optional you can get the 1.8 compiler (you can then switch compiler levels between 1.7 and 1.8 in Preferences -> Groovy -> Compiler), the SDK and the Maven integration m2e.

Key Features of the plugin are: Syntax highlighting, Type inferencing, Compile and run Groovy classes and scripts in Eclipse, Outline view for Groovy files, Auto-completion, Refactoring, Source code formatting, Basic debug support, Groovy 1.7 compiler and Groovy 1.8 compiler.

Quickstart in Eclipse

  • Create a new Groovy project “groovyProject” via File ->New -> Other -> Groovy
  • Create a new package “org.bigdev.groovy”
  • Create the class “GroovyTest” via File -> New -> Other -> Groovy -> Groovy Class
  • Create the following code:
package org.bigdev.groovy

class GroovyTest{
  static void main(def args){
    def greeting = 'Hi '
    def list = [1,2,"bigDev"]
    list.each{ println "$greeting" + it +'!'}
  • Select the class, right click and select Run As -> Groovy Script

Making existing Eclipse Projects Groovy

If you want to add Groovy scripts/classes to your existing Eclipse Project, e.g. a Dynamic Web Project, you can add the Groovy Project facet to it: This is actually not a Eclipse facet, rather do

  • right click the project in the package explorer
  • Configure -> ConvertToGroovyProject

Otherwise the Groovy files won’t compile right (groovyc’s needed). It worked for me.

This way the Groovy libraries are added to the build path (the supplied Eclipse Groovy is not the latest…); or if you have a web project manually add them to the WEB-INF/lib, if they aren’t provided on the AppServer.