Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 11. Integrating Groovy > Getting ready to integrate - Pg. 287

Chapter 11. Integrating Groovy We build too many walls and not enough bridges. --Isaac Newton One of the biggest advantages of Groovy (even one of the reasons for its inception) is the fact it integrates natively with Java because both languages run on the same platform. It is important to understand what makes Groovy such an attractive option when you need to embed a scripting language in your application. First of all, from a corporate perspective, it makes sense to build on the same platform that most of your projects are already running on. This protects the investment in skills, experience, and technology, mitigating risk and thus costs. Where Java isn't a perfect fit as a language, Groovy's expressiveness, brevity, and power features may be more appropriate. Conversely, when Groovy falls short because of the inevitable trade-off between agility and speed, performance-critical code can be replaced with raw Java. These balancing decisions can be made early or late with few repercussions due to the close links between the two languages. Groovy provides you with a transparent integration mechanism that permits a one-to-one mix-and-match of Java and Groovy classes. This is not always the case with other scripting solutions, some of which just provide wrappers or proxies that break the object hierarchy contract. This chapter will show you how to integrate Groovy with Java in various ways. First we'll examine three facilities provided by Groovy: GroovyShell , GroovyScriptEngine , and GroovyClassLoader . We will then consider the scripting support provided by the Spring framework and Java 6, code-named Mustang. You will see that by integrating Groovy and Java, you can leverage the vast libraries of available Java classes