Embedding Groovy into Java
There are plenty of scripting languages available at the moment on the JVM. Some of them only offer expression language support for data binding and configuration needs, for example, MVEL (http://mvel.codehaus.org/) and SpEL (Spring Expression Language, http://www.springsource.org/documentation). Others provide a fully featured programming language. Examples of these are JRuby, Jython, Clojure, Jaskell, and of course, Groovy.
In this recipe, we will show you how to benefit from Groovy scripting from within your Java application.
Getting ready
To embed Groovy scripts into your Java code base, first of all, you need to add groovy-all-2.x.x.jar
library to your class path. Or if you are using Java 7 and want to take advantage of the invokedynamic
optimization, you should add groovy-all-2.x.x-indy.jar
instead (see also the Running Groovy with invokedynamic support recipe in Chapter 1, Getting Started with Groovy).
These libraries are located inside the Groovy distribution...