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 ...

Get Groovy 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.