ThirstyHead Tech Spike: From Struts to Grails in a day
Struts is the de-facto web framework for Java web developers. It has been with us since 2001. Struts enjoys unprecedented success -- most surveys place its market share between 60% and 70%. But sometimes you can be a victim of your own success. Many companies are now looking to upgrade their aging Struts-based web infrastructure, and the traditional message of "knock it down and build it again from scratch" simply isn't an option.
Grails was released in 2008. It marries the features of a modern web framework with the need for legacy support for Struts. Companies like Wired.com, LinkedIn.com, and Sky Television all take advantage of Grails' power and ease of use. Maybe it's time for you to do the same.
Grails is written in Groovy, a language that offers seamless interoperability with legacy Java. You can use 100% of your existing Java code as it stands right now. If you have Hibernate HBM mapping files, Grails can use them unchanged. If you have Hibernate-annotated JavaBeans, Grails can use them as is. Pathological legacy database schemas? No problem. A Grails application is deployed as a standard WAR file, complete with WEB-INF/lib, WEB-INF/classes, web.xml, and everything else a seasoned Java developer would expect to find.
But Grails isn't simply "more of the same" -- come find out how you can gradually migrate to the latest features like convention over configuration, scaffolding, metaprogramming, and more.
Objective
To migrate existing Struts applications to Groovy and Grails, reusing as much as the legacy software as possible.
Goals
This class is targeted at developers who have successful Struts applications already in production. We'll start by using Groovy to strategically ease the pain points of an existing Struts application. Your organization might decide to stop there. However, we'll begin migrating one portion of the Struts application at a time into Grails until we eventually have something that is ready for the 21st century. Who knew that Struts development could be exciting again?
Course Outline
Introduction to Groovy
You'll install Groovy and configure your text editor or IDE -- IntelliJ, NetBeans, and Eclipse all offer Groovy support. Next, you'll dive head first into Groovy's collections, easy iteration, and syntactic shortcuts.
Java and Groovy Integration
Groovy is written by Java developers, for Java developers. In this section, you'll get an introduction to GroovyBeans (or POGOs). You'll see how Groovy auto-generates your getters/setters and adds powerful getProperty()/setProperty() methods. Calling Java from Groovy and Groovy from Java is a piece of cake if you set up the joint compiler in your build script.
Incorporating Groovy with a Legacy Struts Application
Once you have a little bit of Groovy under your belt, you'll be anxious to add it to your existing legacy application. We'll explore ways of mixing in Groovy that is neither disruptive nor destructive. These are your first baby-steps towards Grails.
Running Your Legacy Struts Application Inside Grails
Grails offers a Struts plug-in that allows you to run your application unchanged. Grails will read your struts-config.xml file and route traffic among your Actions, ActionForms, and so on.
Grails and Legacy Databases
In this section, we’ll talk about skinning existing databases with Grails. The real power of the Grails Object/Relational Mapper (GORM) shines when you see how your class and field names can differ dramatically from the underlying table and column names. You’ll see the static mapping block used in POGOs, as well as Java classes with EJB3 annotations and Hibernate HBM files. GORM is a thin Groovy facade over Hibernate, so you can use all of your existing hard-earned Hibernate knowledge without unlearning a thing.
Grails and Struts Side-By-Side: a Long-Term Migration Strategy
In this last section, you'll see how to deploy your Grails application along with your legacy Struts application. We'll discuss application server configuration, session-sharing strategies, authentication and authorization reuse, clustering, and more. Rather than doing a "big bang" migration that is all or nothing, you'll learn how to run the two side-by-side and gracefully age out the Struts application that has served you so well.