The Artima Developer Community
Sponsored Link

Java Community News
Groovy and Enterprise Java APIs

1 reply on 1 page. Most recent reply: Mar 28, 2007 9:20 AM by Marc Stock

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Groovy and Enterprise Java APIs Posted: Mar 27, 2007 3:35 PM
Reply to this message Reply
Summary
A pair of short articles explores the extent of Groovy's integration with Java enterprise APIs: Guillaume Laforge reports on using Groovy with the recently released Guice IoC framework, and Romain Guy shows how to use the Java Persistence API from Groovy.
Advertisement

Since its 1.0 release late last year, Groovy has been steadily gaining momentum, as recent articles and blog posts indicate. One of Groovy's main attractions as a scripting language is that it works easily with the wealth of Java APIs in use in enterprises. A recent pair of short articles demonstrate how Groovy works with two enterprise-oriented Java frameworks: The recently released Guice IoC framework, and the Java Persistence API.

In Guicy: a Groovy Guice?, Guillaume Laforge, a leader of the Groovy project, notes that Groovy's support for Java annotations is one of the main enablers for Groovy scripts to call into Java enterprise APIs:

I'm sure [Groovy's annotation support] will propel Groovy as the de facto enterprise scripting solution leveraging the wealth of frameworks and libraries using annotations.

Guice, an IoC framework released by Bob Lee under the Apache 2.0 license, makes extensive use of annotations to provide dependency injection for enterprise applications. Guice is positioned as an XML-less way to accomplish in IoC what Spring does with XML configuration files. Laforge provides a complete example of using Guice from a Groovy script, noting that:

I'm not sure I'd use Guice for a customer project anytime soon, but for small projects where I want a xml-free DI framework, that might do! However, I might be tempted to use Grails' Spring bean builder instead, since it's a pretty cool way to avoid the usual XML-hell when working with Spring.

In a similar vein, Romain Guy writes about using the Java Persistence API, JPA, from Groovy in a desktop application, in Persistence Made Easy with Groovy and JPA:

I was recently looking into using JPA (Java Persistence API [or Achitecture]) in desktop applications to persist the UI’s state. After all, that’s what JSR 296’s reference implementation relies on to save the frame’s size and position... What struck me ... is how clean and easy the code looks. Yet, I wanted something even easier and cleaner so I tried to use JPA/TopLink with Groovy. I encountered a few issues but ... I finally have something that works.

The very first step to use JPA with Groovy is to write your entity bean that you will persist to the database and later retrieve.... Because we are using Groovy, the getters, setters and constructors are automatically generated for us.

Having resolved a few class loading conflicts between Groovy and the Oracle TopLink implementation used in the example, Guy shows how just a few lines of Groovy code that calls into the persistence API can facilitate sophisticated data access for an application.

If you've already used Groovy in your projects, what role did Groovy play in your enterprise architecture? And if you're just thinking about using it, where do you think Groovy would fit best in a Java enterprise application?


Marc Stock

Posts: 17
Nickname: salient1
Registered: Mar, 2007

Re: Groovy and Enterprise Java APIs Posted: Mar 28, 2007 9:20 AM
Reply to this message Reply
I've used Groovy primarily to write utility scripts. It's amazing what you can do with so little code. However, I haven't tried anything like what Romain or Guillaume have done. Now that I know you can integrate Guice and JPA functionality into Groovy (not that there was any reason to believe that you couldn't), I'll have to give it a shot.

Flat View: This topic has 1 reply on 1 page
Topic: Image Scaling in Java2D Previous Topic   Next Topic Topic: Enunciate Helps Code-First Web Service Development

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use