How to change default server port for Grails application

Print Friendly, PDF & Email

As a web developer, all of us are aware of the number 8080 as the holy port nobody can forget. In Grails based applications, there is no exception at all.

For some reasons, we might need to run multiple grails application on our laptop. In this situation, knowing how to change the default port of grails application would be valuable.

In this post, I will show you how to obtain the purpose by doing few steps below.

Prior to grails 3.x, we can change the port by running the application using following command:

grails -Dserver.port=8181 run-app

This command sets the given port temporarily. You have to use this command each time when you run the application from the terminal or console.
If you want to change port permanently, i.e., the application by default runs on other port than 8080, you can easily fix the port number by adding following line in your BuildConfig.groovy file:

grails.server.port.http=8181

A few years ago, grails 3.x was released and they have changed the way of changing the default port. This is right to grails 4.x though there are lots of changed and improved.

For Temporary change
Run the application using following command from the terminal where the project locates:

SERVER_PORT=8181 grails run-app

For Permanent change
Add following line in your application.yml file

server:
   port:
      8181

Or, add the following line in your application.groovy file
server.port=8181

Hopefully, these tricks would bring a convenient way for you to change the server port of your Grails applications.

All constructive comments are welcomed. If you are willing to contribute financial support for our website, please follow the instructions below.

One thought on “How to change default server port for Grails application

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code

This site uses Akismet to reduce spam. Learn how your comment data is processed.