Vita Rara: A Life Uncommon

Groovy Works


Categories: | | | |

What is Groovy Works?

Groovy Works is a marriage of the Groovy programming language, Struts 2 and the Spring Framework.

Using Groovy Works you can develop your "Java" web application and avoid time consuming re-deployments and re-starts. Using Spring's support for dynamic re-compilation of scripted beans you can simply code, save, test in your browser. No need for costly recompilation, package, deploy, restart cycles.

Right now Groovy Works exists as a Struts 2 Plug-in, and an example application. Groovy Works depends on Spring 2.0.3.

Why call it "Groovy Works"?

Primarily because I conceptually see this going beyond just being a Struts 2 plug-in. Groovy, and all the dynamic scripting languages, seem to be changing the face of web development. My vision of Groovy Works is focused on eliminating the re-compile re-deploy cycle, and dramatically improving developer productivity. I remember the days of working in PHP, saving my file, and hitting reload in my browser.

Anyway, I tried coming up with some contraction of Groovy and Struts, and it really didn't quite work. Struts 2 is based off of WebWork 2, which is based on XWork 2. So, I knocked the Web off the beginning of WebWork, and put Groovy there, added an "s" on the end, and voila, Groovy Works. In the end it's just a name. Got a better one?

I thought of Groovy Struts, but seeing as this only works with Struts 2, Groovy Struts 2 just didn't have the right ring to it. Thus, Groovy Works.

Is Groovy Works a new Web Framework?

Not really, at the moment. Currently Groovy Works is simply a method of using the Groovy language to develop an application using Struts 2 and Spring. It's just a Struts 2 plug-in and a methodology, with an example.

What can Groovy Works do for me?

Save time. This was my primary motivation in getting all of the moving parts working together.

I'm in the middle of a large Struts 2 project, and recently moved it to Maven and started using the Jetty plugin. The beauty of being able to edit my JSP files and just hit re-load in my browser got me thinking. Then I started implementing my Struts 2 actions in Groovy. I did some more research and the idea of reloading the actions automatically came to light, along with Spring's support for scripted beans. So, I thought, "wouldn't it be nice to just start the servlet container and code, without the hassle of restarts?!?!"

Can I use Groovy Works with my existing projects?

Most likely. If your project is already using Spring 2 and Struts 2 then you should be able to start using the techniques of Groovy Works simply by adding Groovy, and the plug-in to your project and adopting its techniques. Groovy Works is really just a technique of using Groovy, Spring and Struts 2 together.

How do I get started with Groovy Works?

Download the plug-in and install it to your Maven repository.

  • Unzip it in a directory: tar xfzv groovyworks-spring-plugin.tar_.gz
  • Change directory to the groovyworks-spring-plugin directory: cd groovyworks-spring-plugin
  • Install the artifact with Maven: mvn install

Then download the sample application and try it out.

  • Unzip it in a directory: tar xfzv groovyworks.tar_.gz
  • Change directory to the groovyworks: cd groovyworks
  • Run the application with the Jetty plugin: mvn jetty:run
  • Point your browser at http://localhost:8080/groovyworks/

Now what?

Edit src/main/groovy/groovyworks/MyServiceImpl.groovy and change the message, save the file. Now, reload your browser. You should see whatever you changed your message to on the page. No application restart. You can edit your service bean to your hearts content and just keep reloading. (You do need to run 'mvn compile' after you save to copy the Groovy files to the target/classes directory. I'd like to eliminate that step though.) You can do the same thing with you action. You can also edit the JSP and just hit reload, thanks to Jetty.

What else needs to be done?

A lot.

It would be nice if the Maven Jetty Plugin could either be configured or modified to place the groovy files from the source tree into the classpath. (Update: I have this working using the testClassesDirectory setting for the Jetty plugin. It's kind of hackish, but really shows the potential.) It would also be nice if Jetty could be taught to re-start when a compiled Java class changes, but just keep running when a scripted bean is changed.

The plugin itself needs to be optimized to only recompile the Groovy actions when they change. Right now I believe it is doing it every time. (This is a proof of concept.)

Then there is the issue of boot strapping an application, much like Grails does. This isn't as important to me. I already have a lot of Struts 2 actions in Groovy, and my service and data layers are largely laid out. These features would be nice for new projects though.

Can I use Groovy Works techniques with <insert Java web framework>?

I would think you can. If you are integrating with Spring already you just need to intercept the call to create a bean and see if it is a Groovy script. Take a look at the code in the plug-in for ideas.

Eventually I would like to eliminate the plug-in and just have Spring instantiate the action beans, but there are some issues with that right now.

Some Thank Yous

I would like to thank a few people/groups for all they have done to support Java development:

  • The WebWork and Struts 2 Teams: Thanks for a great framework.
  • Juergen Hoeller and the Spring Team: Thanks for saving me from EJB's! Also, the quick fix of the scripting issues.
  • Chris Tam: Thanks for helping chase down the script beans singleton and AOP issues.
AttachmentSize
groovyworks.tar_.gz36.96 KB
groovyworks-spring-plugin.tar_.gz3.46 KB

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
  • Allowed HTML tags: <a> <img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <h1> <h2> <h3>
  • Lines and paragraphs break automatically.
More information about formatting options