Groovy has been designed to be very lightweight and easy to embed into any Java application system.

You can use

Error rendering macro 'link' : Link needs a name and a URL as arguments.

to embed any scripting language into your Java code; however Groovy offers a lighter weight and closer integration. There are two main approaches

h2 Evaluate scripts or expressions using the shell

You can evaluate any expression or script in Groovy using the

Error rendering macro 'link' : Link needs a name and a URL as arguments.

.
The GroovyShell allows you to pass in and out variables via the

Error rendering macro 'link' : Link needs a name and a URL as arguments.

object.

h2 Dynamically loading and running Groovy code inside Java

You can use the

Error rendering macro 'link' : Link needs a name and a URL as arguments.

to load classes dynamically into a Java program and execute them (or use them) directly.
The following Java code shows an example...

If you have an interface you wish to use which you implement in the Groovy script you can use it as follows

This works fine if the Groovy class implements the inferface MyInterface. myObject can from then on be used as every other Java object implementing MyInterface.

h2 Runtime dependencies

As well as Java 1.4 and the Groovy jar we also depend at runtime on the ASM library constituted of two jars (asm-1.4.1.jar and asm-util-1.4.1.jar). That's it. So just add these 3 jars to your classpath and away you go, you can happily embed Groovy into your application.