Grails is a web application framework written in a programming language called Groovy — which is based on Java.
The Grails platform has an “ecosystem” of powerful development and authoring tools, most of which are open source and well-supported.
Background on Grails
Grails was founded in 2005, originally calling itself “Groovy on Rails” because of the remarkably similar architecture to the “Ruby on Rails” framework.
Groovy comes from the Groovy Programming Language — which first appeared in 2003 as a novel scripting language on the Java Platform, with the code itself being dynamically compiled down to Java Virtual Machine bytecode.
How is Grails Similar to Ruby on Rails?
Groovy follows some similarities with Ruby in terms of influence from Perl and Smalltalk.
Like many emerging technology trends from the early 2000’s, the Model View Controller (MVC) pattern heavily influenced the overall structure of Grails.
The platform was created as a way to allow “coding by convention” — a design paradigm which tries to focus on easy reusable code behaviors and configuration control.
Why did Groovy on Rails Change its Name?
In 2006, the name was changed to Grails, after David Heinemeir Hansson (founder of Ruby on Rails) asked for the name to be changed.
Grails initially was maintained by a group called G2One — which was acquired by SpringSource and then VMware.
However, in April 2015, Object Computing, Inc. announced that they would become the official sponsor of the Grails project, and they will committed to increasing the exposure of the platform.
As an open source project, anyone may contribute, but platforms generally succeed when they also have strong financial backing.
What are the Core Features and Functionality of Grails?
Taking full advantage of the Java platform, Grails accesses the functionality of Hibernate and Spring, in a single interface under a consistent framework.
This allows Grails to be persistent, use dynamic tag libraries for components, and have fully extensible support for Ajax — allowing for live applications.
How Does Grails Differ from Other Java Frameworks?
Beyond that, Grails is built in a way that distinguishes it from other Java frameworks — it does not require XML configuration and is ready for use without deeper setup.
Cutting this reliance on XML for setting up page Controllers means that Grails is a “High Productivity” environment.
This means that less time is spent on setting up the development units, which in turn means that more time can be spent on site production.
Grails thereby allows developers to setup quickly and get started right away.
Main Grails Features
Environment configuration can be extended though, by adding dynamic methods called “mixins” — which add additional class features in a way that works as though it was compiled, but does not require a recompile.
This allows for dynamic methods to flourish and are often used throughout a project.
At a high level, the features of Grails can be summarized in a concise but powerful list:
Flat Learning Curve — taking less time to setup and emphasizing “coding by convention” — the API for Groovy is an easy jump for Java developers
Java Integration – deeply rooted support from the parent technology Java, Grails integrates with Jave Virtual Machines and Containers
Powerful Tools — with strong application support for Object-Relational Mapping and NoSQL, structuring powerfully user-driven Views is easy
Domain-Specific Languages — Grails is a language built for the web, and supports common web conventions like markup languages and modeling languages
Plugin Extensibility — through the Grails Ecosystem and through custom means, additional framework layers can be added for rapid deployments
Other Popular Grails Features: Domain Model, Grails Object Relational Mapping, and Domain Class
This combination of features means that persistence is an emphasized aspect of the platform.
The Domain Model which controls the data layer uses something called Grails Object Relational Mapping (GORM) — allowing for “domain classes” which are saved and automatically made persistent across the project.
Setting something as Domain Class will automatically add “Dynamic Instance Methods ” which make it really simple to setup relational data.
For example, by declaring a “Book” Domain Class with encapsulated Title and Author data — it becomes very easy to Save new books, or to Delete, Count, or Find existing books. No data layer setup needed, everything is handled by Grails.
Why Should I Use Grails and What are The Alternatives?
Grails is a long established platform with strong developer support and a trajectory for growth.
It takes the best feature of Java and makes it simpler to create web applications.
Similar tools do exist, the most notable being JRuby, “Play” Framework, and the more recent Juzu framework.
Choosing the right platform entails comparing the user stories for the intended project against the capabilities of each framework, and figuring out where the most overlap exists.
What are the Pros and Cons of Using Grails?
Grails is a very attractive option for those looking for a Java alternative. It’s a widely used language and has been used by a lot of large-scale businesses like Walmart and LinkedIn.
Its main features, including XML processing and the ability to utilize the same codes to perform different actions, make it quite popular.
It can help to create a very rapid development cycle.
Some Pros of Using Grails
Below you’ll learn a few more reasons that Grails might be a solid choice for your next project:
The documentation and library (highlighted above) are very extensive and in-depth
The development cycle with Grails can be very rapid
There is a wide range of plugins available to extend functionality and make your job easier
CSS can be very easy to manage since the framework is so simple.
Dynamic conjuration is supported, so you don’t have to restart your server
The code validation can be much simpler and faster
Seamless integration with the GORM data access toolkit that’s equipped with an extensive set of APIs
Can easily integrate with any existing Java code
Code is easy to maintain as it’s very concise and clean
GSP or Groovy Servers Pages can be installed and used via a plugin
Cons to Using Grails
However, like any other language, it’s not perfect. Drawbacks include being more error-prone, since it is a runtime language. Plus, you’ll have to purchase IntelliJ Idea since most integrated development environments don’t have it.
Finally, it does integrate with GORM, but not any other Object-relational mapping.
How to Set Up Grails
Setting up Grails is fairly straightforward but depends on the operating system you are using. Grails.org maintains a stable binaries on their Download page.
The easiest way to handle Grails and keep it up to date is to use the Groovy enVironment Manager (GVM) — Windows users will need to use a parallel application called Posh-GVM — which uses PowerShell. With GVM installed, installing Grails can be done simply on the Bash terminal line.
Grails is supported by many common Interactive Development Editors (IDEs) and text editors, have syntax highlighting and auto-complete for Grails — including IntelliJ IDEA, Eclipse, Sublime Text, Textmate, and Notepad++.
For everything beyond this point, the development of the website, the database configuration, and any further work is entirely up to the developer.
Grails.org has a good Learning Center — and beyond that, many different starter templates exist officially or in open source projects around the web.
Grails has a strong community, is well supported on StackOverflow, and hosts many different events around the year.
How to Host Your Groovy and Grails Application
When the time comes to host your Grails app, you’ll need to find a suitable hosting environment that supports Java applications.
Typically this means you’ll want to go with a cloud or VPS host. The benefit of this is that it will also allow your app to scale and you won’t be limited by server resources.
Here are step-by-step instructions for getting started:
Choose a host and obtain the necessary FTP information.
Download your Grails app, which will end up being a .war file.
Connect to your host via Terminal or your software of choice.
Upload your war file to your server.
You might have to restart your server after upload to see the changes made.
What to Look for in Grails Hosting
When you’re looking for the right Grails host to host your new application you’re going to have to lot of different options.
Your only base requirements will be a Linux host that allows root level server access. Your choice will depend upon your overall budget and the size of your app, along with how much bandwidth you require.
Regardless of your situation, you’ll want to look for the following features:
Either a cloud or VPS host. This will allow you to scale your server resources as needed and give you flexibility as your application grows.
An ample amount of bandwidth and storage. You can set your storage prerequisites when you’re uploading your application, but you’ll want to have room to work with.
Solid security features and regular backups. Although not completely necessary, these features are always nice to have in a host and make it so you don’t have to do everything yourself.
Top Three Hosts for Grails
Grails.org recommends hosting with Secure Shell (SSH) and FTP (SFTP) access for security reasons and ease of use.
There are many different dedicated providers available who focus on Grails hosting, but any Linux virtual machine with root level privileges will work. The following three companies are great places to start your search for a Grails-friendly host.
SiteGround’s cloud options give you up to 8 CPU cores, 5 TB of data transfer, daily backups, and 24/7 support. Plus SSD storage.
SiteGround has an excellent reputation for going above and beyond with service, their technology stack, and with fostering an active community with users. I’ve been consistently impressed with this particular hosting company.
All of their cloud options are fully managed and autoscalable.
A2 Hosting offers a fast and affordable Grails hosting option. Its cheap plans are equipped with plenty of storage and bandwidth for your needs.
Plus you’ll have root access and the ability to scale your site up to a higher plan if needed. A2 Hosting is also equipped with a one-click install of Grails using Webuzo. With developer access to your server, you also get complete shutdown, boot, and reboot control.
If you don’t need as much processing power, data transfer capacity, or storage as what’s offered by SiteGround, consider HostGator as the budget option.
This host provides data mirroring, integrated caching, and failover with all cloud plans. To preserve the budget pricing, backup is an add-on available for a fee. They also offer 24/7 customer service.
About Kevin Wood
Kevin got his start as a web developer. Now he spends his time as a technical writer and poet. His main interests are technology and human potential. When he's not diving headfirst into technical topics, you can find him scrawling lines of poetry and getting lost in the woods.
Connect with Kevin
Who's Best for Grails Hosting?
We think SiteGround is the best choice for Grails.