Table of contents
1.
Introduction
2.
What is Grails?
3.
What is deployment?
4.
Grails-Deployment
4.1.
Standalone
4.1.1.
"grails run-app"
4.1.2.
Runnable WAR or JAR file
4.2.
Container Deployment
4.2.1.
WAR file
4.3.
Deployment Configuration Tasks
4.3.1.
Setting up HTTPS and SSL certificates for standalone deployment
5.
Frequently Asked Questions
5.1.
What is Grails?
5.2.
Is Grails an MVC framework?
5.3.
What is better, grails or spring?
5.4.
What is a grail application?
5.5.
How does the Grails framework operate?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Grails-Deployment

Author Manan Singhal
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hello Ninjas! Have you ever wondered what is Grails and how it works?. Don't worry, We have got you covered. Welcome to our article on web applications using Grails. A web application is an application that users can access through a web browser. Grails is an open-source web application framework that uses the Apache Groovy programming language.

Grails-Deployment

In the article, we will learn about a deployment in Grails. But before that let's learn about Grails.

What is Grails?

Grails is a high productivity framework. Grails was initially known as Groovy on Rails when it was first released in 2005, but the name was changed in 2006 due to a disagreement with the inventor of Ruby on Rails.

Grail's purpose was to create a Java web framework by combining technologies such as Hibernate and Spring into a single interface.

Grails

In the end, the programmers produced a robust web application framework for the Java Virtual Machine built on top of Groovy and Spring Boot.

What is deployment?

Deployment is how developers deploy applications, modules, updates, and patches to users. The methods developers use to create, test, and deploy new code impact how quickly and well a product responds to changes in customer preferences or requirements.

Deploying

In short, The process of installing, configuring, upgrading, and enabling a single program or group of apps that make a software system usable, such as facilitating a specific URL on a server, is known as application deployment.

Grails-Deployment

Now let's learn how can we deploy our apps on grails.

Standalone

"grails run-app"

You must be familiar with this strategy because of you have ran this command while developing this application. The web application is loaded from the development sources by a Tomcat server. Allowing it to take advantage of any modifications made to the application files.

Running the application using a production environment:

grails prod run-app


Running the application using the bootRun Gradle task:

./gradlew bootRun


Specifying environment supplying grails.env system property.

./gradlew -Dgrails.env=prod bootRun

 

Runnable WAR or JAR file

Utilizing the new functionality for runnable JAR or WAR files is another deployment method in Grails 3.0 or higher. 

Jar file

Run the grails package to generate runnable archives.

grails package


Using assemble Gradle task:

./gradlew assemble


Run the WAR file (or the JAR file) using the Java installation:

java -Dgrails.env=prod -jar build/libs/mywar-0.1.war    (or .jar)

Container Deployment

Grails apps can be deployed to an Application Server or Servlet Container.

WAR file

Using a WAR file to deploy Grails applications to an existing Servlet container is a typical practice. Multiple apps can be deployed on the same port using various pathways.

WAR file

Creating a WAR file:

grails war


This will generate a file in the build/libs directory that can be deployed to a container.

Be aware that Grails will by default include a runnable version of Tomcat inside the WAR file. While deploying, if you deployed it to a different version of Tomcat, this could cause issues. Before sending it to your production container in build, you should either remove the Tomcat dependencies or change the scope to test implementation if you do not wish to use the embedded container in build.gradle:

testImplementation "org.springframework.boot:spring-boot-starter-tomcat"

Deployment Configuration Tasks

Setting up HTTPS and SSL certificates for standalone deployment

Add these properties to application.yml:

server:
    port: 8443
    ssl:
        enabled: true
        key-store: <the-location-of-your-keystore>
        key-store-password: <your-key-store-password>
        key-alias: <your-key-alias>
        key-password: <usually-the-same-as-your-key-store-password>


These settings control the Tomcat container for production deployment. The properties can be specified on the command line. 

Example: 

Dserver.ssl.enabled=true -Dserver.ssl.key-store=/path/to/keystore.

Frequently Asked Questions

What is Grails?

Grails is a free, open-source web application framework using the Apache Groovy programming language adhering to the code-by-convention concept. It is a high-productivity framework.

Is Grails an MVC framework?

MVC apps are created using the Grails MVC platform. The MVC architecture is built-in to Grails. In MVC, model classes should represent the domain objects while the controller represents the application's flow. So, yes Grails is an MVC framework

What is better, grails or spring?

Reviewers found Grails to be generally easier to use, set up, and conduct business with when comparing the two options. Reviewers, however, preferred Spring Framework's simplicity of management. They believed that Spring Framework and Grails better fit their businesses' needs.

What is a grail application?

The Groovy programming language is used by the open-source web application framework known as Grails. By adhering to the "code by convention" philosophy, offering a standalone development environment, and keeping much of the configuration information hidden from the developer, it is meant to be a high-productivity framework..

How does the Grails framework operate?

The Grails framework uses the Model-View-Controller (MVC) design pattern to divide tasks inside the application and streamline its architecture. In your system, model classes should represent the domain objects. The application's flow should be under the control of controller classes.

Conclusion

In the article, we learned about a deployment in grails. We hope this article will help you understand the concept of deployment. Check out our other blogs on the topic Grails:

Refer to our guided paths on Coding Ninjas Studio to learn about Data Structure and Algorithms, Competitive Programming, JavaScript, etc. Enroll in our courses and refer to our mock test available. Have a look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass