Skip to content

Wakaleo Consulting

  Home
Changing ports with Grails E-mail

When you run a Grails application from the command line (using grails run-app, for example), it will run on port 8080 by default. This also applies when Grails runs web tests such as Selenium, Canoo webtest or HTMLUnit. If you have web tests in your application, Grails will automatically start up the application before running the tests, which is just what you want.

However, the port 8080 is not always what you want. You may need to run your Grails app on a different port if port 8080 has already been taken by another application. This is particularly the case on build servers, for example. The simplest solution is to set the server.port property on the command line, as shown here:


$ grails run-app -Dserver.port=8888

This is good as far as it goes, but has some limitations. Firstly, what if you always want to use the port 8888 for your Grails apps? Secondly, if you are using Hudson with the Grails plugin, this plugin doesn't currently let you provide command-line options like this. A work-around is to invoke grails from the command line in Hudson, as shown here:


$ grails -Dserver.port=8888 test-app

Note that Grails is finicky about the position of command-line parameters - they need to go after the "grails" command and before the target.

Another solution is to change the default port used by Grails itself. In Grails 1.1 at least, the trick is to modify the $GRAILS_HOME/scripts/_GrailsSettings.groovy file. In it, you will find a reference to the default port (8080). Just change it to whatever you require, and Grails will always run on this new port. The modified entry might look like this:

serverPort = getPropertyValue("server.port", 8888).toInteger()

Once this is done, Grails will always run on this port.

Tags See All Tags Add New Tag...

Please Enter New Tags Separated By Comma's
  Or Close

Grails 

Trackback(0)
Comments (1)Add Comment
0
An Alternative
written by Jacob, December 14, 2010
Adding these to conf/BuildConfig.groovy for your project also gets the job done.

grails.server.host="127.0.0.2"
grails.server.port.http="8010"

Write comment

busy
 

Learning Corner

Upcoming courses

Testing and TDD for Java Developers in Melbourne
3 DAY WORKSHOP
Melbourne 2-4 April
 
Testing and TDD for Java Developers in Sydney
3 DAY WORKSHOP
Sydney - 26-28 March
 
Testing and TDD for Java Developers in Canberra
3 DAY WORKSHOP
Canberra - 1-3 May