Grails:
Accelerating
J2EE
Application
Development
A closer look at how Grails changed the GAME…
Introduction:
Let’s face the reality: developing web applications is not at all easy. This problem
has been aggravated in today’s web application development environment, where
applications expected to fall into the Web 2.0 category comprise a lot of
technologies like HTML (Hyper Text Markup Language), CSS (Cascading Style
Sheet), AJAX, XML, web services, Java and the database. Moreover, on the top of
these technologies, there are lots of open source framework choices like MVC
frameworks and Ajax frameworks. To feed the fire, while the complexity of
creating web applications continues to grow, expected turnaround times continue
to decrease.
In the past years, the Java community has made many efforts to solve these issues
by creating applications using the Java platform, Enterprise Edition and Java 2
Platform, Enterprise Edition (J2EE). All of these platforms have proven to be robust
and scalable, but they don’t allow rapid agile development. Moreover, Java EE
proven often that it was written with a much lower technical level, not with an
application level abstraction. This is the main reason that different frameworks
like Struts, Spring and Hibernate have been created.
Today’s Java-based web frameworks are partial solutions, you still need to manage persistence, deployment etc. all on your own. Struts, Spring & Hibernate are not bad, they are okay but:
It’s very time consuming to start or set up any project. It becomes complicated quite rapidly.
There are so many layers including DAOs, DTOs, abstraction layers and so on.
Too many configuration files, which means too much XML for everything.
These at the end make ORM
persistence more difficult to master
and get it done appropriately. Too
many layers and configuration files
lead
to
complete
disorder
&
confusion.
Great efforts have been made in the
field of Java-based web application
framework,
but
building
web
application rapidly using them still
seems like a lot of work.
Here’re the problems...
So, what’s the solution? We’re moving into a new era of web frameworks and
the expectation of enterprises or companies is a full-stack solutions.
Enter
Grails!
Grails addresses all the fundamental flaws present in Java web
application development without compromising the platform. Grails is an open
source web development framework that incorporates various open source
frameworks and offer great features. In this white paper, we’ll discuss in detail
about Grail’s architecture, fruitful commands and how to utilize the Grails’
powerful scaffolding feature to build applications. We’ll also compare Grails with
other existing Java web frameworks to know how it accelerates J2EE application
development.
Grails –
A First Look
Grails is an open source web framework powered by the Groovy – language based
on the Java Virtual Machine (JVM). By avoiding a lot of unnecessary configuration
details, it brings a clear & rapid web development environment. Grails runs on a
standard servlet container, which empowers you to choose your own
presentation technology, whether it's based on JSP or GSP.
Grails is built on proven and rock-solid OSS bricks:
Spring: IoC, DI, Spring MVC, Transactions and so on…
Hibernate: ORM & Querying mechanism
Groovy: For everything that matters
Quartz: For Job Scheduling
AJAX: Integrating Different Libraries
Jetty & HSQLDB: For Rapid Development Cycles
Grails is an MVC framework, but it's not at all like an average Java MVC
Framework. Unlike other MVC frameworks, Grails domain classes are dynamically
persistable and can create the elementary database schema. Grails offers
extremely simplified and speedy agile development. It eliminates most of the
standard MVC configuration and deployment descriptors by using initiative
conventions. It is ready to run and offers great templating, custom tags and tons
of other benefits to the developers.
What is so special about “
Grails
”?
As it’s easy to start with, Grails offers quite a smooth start to seasoned as well as beginner Java developers.
With the help Groovy, if you write some Java code, the same code would be much shorter while giving
the same result. Do you have any custom Java library and want to reuse them? No problem! You simply
have to import them like you always do with regular Java files.
Grails enables developers to write DRY (Don’t Repeat Yourself) code. You can easily use any existing Java
code in Grails.
Filters impose cross-cutting behaviors to web applications to include various capabilities like
security, tracing, logging and so on. With REST support, Grails enables existing web objects to
be transformed to the XML or JSON, with tasks being automated.
ORM DSL enables Grails to support legacy databases within the applications.
JNDI enables Grails to utilize Spring to look up any existing programming objects such as data
source.
No restarts needed when changing the code.
Adding new features is quite easy as it is written in Dynamic language.
HTML/CSS programmers can easily work on a layout without involving coders.
Define your own template and use them within your Grails applications with ease.
WOW Factors of Grails
Moreover, you can leverage from the full MVC support and tons of useful plug-ins. In addition, Plain Eclipse,
STS (Spring tools suite), GGTS (Groovy and Grails tools suite), Intellij idea and NetBeans offers fully
implemented and out-of-the-box or standard plug-in support for Grails projects, which really boost up the
development process. Creating custom tags in Grails is hassle-free, all thanks to the rich plug-ins database
that make it very easy to add any AJAX or JavaScript based solutions.
Digging in Grails’
Architecture
:
Now that you are aware about the power of Grails and various open source frameworks included in it, it’s
time to start digging the Grails Architecture. The figure shown below depicts the architecture of the Grails
graphically:
The figure clearly shows that the foundation of Grails is the Java Virtual Machine. It is based on the Spring
Framework. Moreover, they are published by SpringSource itself.
SiteMesh is the framework that basically deals with the layout. It also implements the decorator design
pattern to build HTML pages.
GORM enables us to establish the relationship between objects and relational schema Groovy. It is based on
Hibernate, and it is a layer of abstraction over the database. By default, Grails uses HSQLDB, which is a
database integrated with the Hibernate.
Gant is a layer above the popular “ant” for writing tasks groovy instead of XML. Grails application is basically
Grails Changed the game:
How Grails target the pain points of developers?
Leveraging from the Groovy as the bottom-line dynamic language, Grails made it possible for the developers
to create a Book object and query it using dynamic methods like Book.findByTitle(“Grails”) or
Book.findAllByDatePublishedGreaterThanAndTitleLike(myDate, “Grails”), without the existence of such
methods of the Book object.
Moreover, Grails was built on Spring, Hibernate and other libraries that are already quite popular in
enterprise Java- using which developers already building applications. Finally, Java developers had an
opportunity to take all the ideas that Rails had brought and apply them to scalable and robust
enterprise-level web application development, without compromising their skills, libraries or infrastructure behind.
Still not convinced how Grails changed the game and target the pain points of developers? Let’s discuss
some out-of-the-box features or Big Ideas of Grails that have helped Grails to dominate the emerging
next-generation Java web framework market.
Big Idea #1:
Convention over Configuration
Instead of using lots of XML configuration files, Grails focuses on conventions to make application
development process easier and more importantly “Productive”. This at the end exhilarates the
principle of DRY (Don’t Repeat Yourself). Moreover, Grails also include a command-line interface
that can be used by developers to create Grails artifacts and enforce the conventions.
Big Idea #2:
Philosophy of AGILE
Grails is an agile framework. By utilizing the dynamic language Groovy, Grails help developers to
make things that were a real pain point in Java. Whether it’s all about processing a form post,
implementing tag libraries or writing test cases, there is enough conciseness and expressiveness
in the framework that really makes these operations easier and maintainable. It brings an entirely
new level of agility to the Java web application development.
Big Idea #3:
Rock-Solid Foundations
Of course, Grails itself is a source of innovation and out-of-the-box ideas, the framework is built on some of the rock-solid and proven technologies like Spring and Hibernate. These two are the technologies that have been used by many existing Java shops due to their reliability. If you’re a newbie Java developer and don’t have any idea about Spring and Hibernate, then also you don’t have to worry at all. Grails will always be there whenever you need it!
The philosophy of utilizing the best of breed components has converted to the other areas of Grails, particularly to the third-party plug-in. For example, scheduling plug-in is built using Quartz, the search plug-in is built using Lucene & compass and the layout engine is made on SiteMesh. Another major benefit of the foundation for the enterprise developers is getting ample technical support & backup.
Big Idea #4:
Scaffolding & Templating
Have you ever tried bootstrapping a Spring MVC by hand? If you have, then you will know that it's not so pretty. You will require a directory of a JAR files, number of bean definition files, an entire set of web.xml customizations, a bunch of POJOs, some of the Hibernate configuration files, a database-creation script and finally a build system to finally turn these all into a running application. It’s quite daunting tasks and may require a whole day for it.
In contrast, creating a running Grails application is a very easy process that involves grails create- app my app, and you can follow it up using grails run-app to view it running within the browser. If you wish to create a controller class, grails create-controller will easily create a shell for you.
Moreover, Grails support scaffolding that help developers to crates applications with create, read, update and delete functionalities with a very little code, enables you to concentrate more on defining the Groovy domain by generating classes with properties, behaviors and constraints. For example, any domain class can be scaffolded by creating a scaffolding controller shown below:
All of this is known as “Dynamic Scaffolding” where the CRUD interface is generated dynamically at runtime. However, using generate-all<domain name>, you can create controller & view, and can customize the code later on. This is called a “Static Scaffolding”. For example, controller class would like:
Big Idea #5:
Out-of-the-box Default Runtime
From the runtime perspective, Grails is out-of-the-box! You can say it by simply seeing the image below. In the image, you can see that web browser is making requests to a Jetty web container. The container simply forwards the request to a controller in a much similar way that you can find in an MVC model. The controller either set or uses data from a domain class. As Grails domain classes are persistable through the GORM framework, you don’t require using a Data Access Object or writing SQL to persist the
objects. Grails utilize an HSQLDB database, which means the database runs within the same JVM as your application and the Jetty web container.
Big Idea #6:
Ease of Java Integration
With Grails, you don’t have to leave behind the impressive collection of Java libraries. Whether it’s a new Java library for interfacing with Facebook or its in-house DTO JARs, moving to Grails will leave nothing behind for you! According the poll conducted by vsChart.com,
50%
of the users have chosen Grails against some of the most popular frameworks like Ruby on Rails and Play!.Big Idea #7:
Incredible Community
One of the most appealing things about Grails is its fascinating and helpful user community. The Groovy and Grails mailing list is a place where seasoned and new users are treated same. Moreover, you can find plenty of third-party websites that are centered around on Grails. For example, Facebook, LinkedIn and grailsworld.com have rapidly become a social networking option for Grails framework. Apart from all these, one of the most amazing things about the community is the every rising list of various 3rd party plug-ins for Grails.
You can find hundreds of time-saving and powerful plug-ins!
JVM Jetty Controller GPS Domain HSQLDB
How
Grails
ACCELERATES J2EE Application Development?
Many enterprises or prospective clients often ask “Why should they go for Grails & how Grails accelerating J2EE application development?” Well, it should have been an easy question to answer. There are plenty of things that can easily explain how Grails can take the J2EE application development to the new highs and why enterprises or companies should go for it.
Let’s have a look at some of the reasons why Grails is great!
1.
Based on Groovy, which means the code is much more concise, expressive and DRY compared to normal
Java code. Moreover, the code length is reduced, which at the end higher developer productivity and less code to maintain.2. Empowers you utilize the power of underlying frameworks! Of course, GORM does a great job of protecting you from direct dealing with the Hibernate. However, if you wish to bypass GORM and directly use the Hibernate API, map POJO or POGO to existing tables, then Grails doesn’t stop you doing that! 3.
Ease of set-up everything & get started. It’s quite an easy task for Java developers to get started
with using the Grails framework for developing web applications. In a survey conducted by OIO, published in April 2012,
16%
of the participants have chosen Grails as their preferred framework.4. Application development using Domain centric approach. Grails puts domain classes at the center of application development, which is a very good thing.
5.
Get rid of frequent server restart
during the application development! While developing applications using Grails, you don’t require restarting the server or web container after making changes everything. It basically uses an intelligent mechanism to reload and apply the changes you made.6.
Testing support. Grails promote testing and offer utilities to make the testing process easier for
developers. Moreover, you don’t have to use any specific testing framework. You can use JUnit, Spock, EasyB, Geb, Selenium, Canoo or any other framework.7.
Clearly separated “Environments”! This is an amazing concept of Grails. It allows you to smoothly
manage environment specific configuration as a part of the code base. If you don’t want to store the environment specific configuration within the code base, then you have ample options to externalize the configuration.8.
Built-in REST support. Grails offers built-in support for REST through URL mappings, Data binding and
rendering objects as JSON or XML.9.
The Tag Lib Authoring mechanism
makes it easy to modularize and reuse the view layer code due to ease with which tabs can be created. It is quite easy to write the tag in Grails.10.
Data binding through command objects. Grails makes it a smooth process to consume and validate
from data through data binding feature, command objects and the ample support for validators in command objects.11. Modularity and reuse through plug-ins base development approach! Grails supports the reuse of code through different Grails applications by modularizing your application in the form of plug-ins. Plugin-centric development approach forces modularity and reuse.
12.
More than 700 plug-ins! The number plug-ins available are a huge. They help developers to incorporate
tons of functionalities and components. The figure shown below indicates consistent growth in number of plug-ins for Grails. The number of plug-ins by 2012 is more than 700. Moreover,50%
of the users have voted Grails in terms of the out-of-the-box features offered by it without configuration and other stuff.Grails
vs.
Other J2EE Frameworks…
Grails
Ruby On Rails
Play! Framework
Features
Scaffolding Full Text Search
Architecture
Development Principles Convention over Configuration Test-Driven development Convention over Configuration Test-Driven development Convention over Configuration Test-Driven development &DRY Design Pattern
MVC, Dependency Injection, Domain Driven
Design, Data Mapper
Active Record, MVC MVC ( Model-View-Controller)
Multilingual
Multilingual content
System Requirements
Operating System JVM Compatible *NIX, Linux, Mac OS X,
Windows, QNX
Cross-platform Programming Language Groovy, Java, Clojure,
Scala
Ruby Java, Scala
Database MySQL, NoSQL, Oracle,
SQLite
MSSQL, MongoDB, PostgreSQL, MySQL, Drizzle, Oracle, Redis,
SQLite, IBM DB1=2
MySQL, PostgreSQL, MSSQL, Hazelcast, IBM DB2, NoSQL,
MongoDB, Oracle, SQLite
More
Multi-user System Extension/Plug-in
(Conditional) Interpreter
Unicode
Multiple Projects Standard Compliance
User Statistics ?
Revision Control
Template Language GSP, HAML, Mustache,
Handlebars JS
ERB, HAML, Erubis, Radius Groovy, Japid, Scala Template Engine Object-Rational Mapping RESTful Code Generation Dynamic Typing Hierarchical Menus Scripting Language Support Groovy, JavaScript, CoffeeScript Ruby, JavaScript, CoffeeScript CoffeeScript, C
Separate Service Layer ?
Web Flows ? ?
Annotation Support ?
Beyond the
Finish Line…
Digging into data searching for insights is always exciting activity. At the end of this white paper, let’s have
a look at some of the most interesting facts about GRAILS…
The interest in Grails is growing worldwide and this is the main reason why Grails Documentation
is translated into Japanese and Korean languages. You can find posts from
Belgium
, blogs from
Brazil
and articles from
Germany
, Grails doesn’t know any LOC!
Job Trends on Indeed.com shows that relative growth of jobs based on Grails is exponentially
rising. Have a look at the graph:
According to the recent research conducted by zeroturnaround, Grails popularity has been
increased by
2%
compared to the results of previous years.
LinkedIn, ESPN, virtuewell, NETFLIX, eHarmony, sky, Atlassian etc. are a few of the giant
companies, who have trusted GRAILS!
About
Cygnet Infotech
Cygnet Infotech is a software services and solutions provider with clients in over 22 countries. Cygnet specializes in custom software development in Java and Grails.