O'Reilly logo

Programming Groovy 2 by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Groovy Scripts from Java

If we want to use Groovy script as is in Java, we can use JSR 223.

Java Specification Request (JSR) 223 bridges the Java Virtual Machine (JVM) and scripting languages (see the Java Scripting Programmer’s Guide in Appendix 1, Web Resources). It provides a standard way to interact between Java and several languages with implementations of the JSR 223 scripting-engine API. We can download and use JSR 223 with Java 5. It is included by default in Java 6.

JSR 223 is an option more suited to other languages on the JVM than to Groovy. Groovy’s ability to jointly compile Java and Groovy lessens the need for something like JSR 223.

To call a (not-precompiled) script from Java, use the script engine. We can obtain ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required