Today, I am going to explain How to run grails application standalone.
Let’s start coding and follow the below steps.
Most of the web application is deployed within external web-server. According to the regular way of deployment, that apps are bundled as war file means war packaging. We can deploy the war in web-server like tomcat and jetty.
Nowadays application builds in micro-services. eg. spring boot application.
We don’t require any external web server. We can create a simple jar file and run the jar using java command.
1 2 3 4 5 |
[php] java -jar deepanker.jar (fileName.jar) [/php] |
In Grails, we have a plugin standalone app which allows to embed a web-server inside the grails application itself. Its provide the advantage to run the grails application as standalone app.
To use this add the plugin dependencies in BuildConfig.groovy file:
1 2 3 4 |
[php] compile "org.grails.plugins:standalone:9.0.0.M4" [/php] |
To create the Jar file using embedded web server :
1 2 3 |
[php] grails build-standalone [/php] |
To run Jar file as a stand-alone application :
1 2 3 |
[php] java -jar /path/to/jar_name.jar [/php] |
We can also add the environment variables while running the jar to run the container with a specific environment configuration :
1 2 3 |
[php] grails -Dgrails.env=prod build-standalone jar_name.jar [/php] |
This plugin has both Tomcat and Jetty web server functionality, we can set the jetty as a default web server. We need to add a below line in BuildConfig.groovy :
1 2 3 |
[php] grails.plugin.standalone.useJetty = true [/php] |
Also, it can be specified at the time of deployment which server will be used to run the application. we can specify the flag values, particularly container.
1 2 3 4 |
[php] grails build-standalone --jetty grails build-standalone --tomcat [/php] |
It removes the external web server dependency and we can run the standalone application with Jar packaging file.
I hope it was helpful for you.
Read more: – https://www.jellyfishtechnologies.com/blog/
Recent Comments