98

I'm using grails 2.0.4. And I want to use port:8090 instead of 8080 for localhost. So need help to change the port to 8090 permanently.

lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
Mamun Sardar
  • 2,679
  • 4
  • 36
  • 44

13 Answers13

136

This solution adds to the answers http://stackoverflow.com/a/10956283/122457. In Grails 2.x, add the following to BuildConfig.groovy:

grails.server.port.http = 8090

See http://forum.springsource.org/archive/index.php/t-97024.html for further details.

Tung
  • 1,579
  • 4
  • 15
  • 32
Chris
  • 3,552
  • 2
  • 26
  • 36
  • This is the better solution. Has less moving parts. – chubbsondubs Apr 07 '14 at 17:37
  • I tried this method and it did not work, is there a specific section in which this should be placed? I stuck it under the `grails.project.target.level` section, and it appeared to have no effect. – Ted Delezene Feb 13 '15 at 22:51
  • @TedDelezene this doesn't go under any other section. Did you restart the application after changing the configuration? - Because only that would reload the configuration (and your change of it). – HumanInDisguise Mar 23 '15 at 14:55
  • Yes I did, and it didn't work for me, however now I just start it with the -Dserver.grails.port.http=49494 option. – Ted Delezene Mar 23 '15 at 18:41
113

There are two options:

  1. Change grails.serverURL in Config.groovy from "http://localhost:8080/${appName}" to "http://localhost:8090/${appName}".
  2. Launch grails with -Dgrails.server.port.http=8090 on the command line. Set the GRAILS_OPTS environment variable to -Dgrails.server.port.http=8090 to have it applied automatically.
GreenGiant
  • 4,930
  • 1
  • 46
  • 76
ataylor
  • 64,891
  • 24
  • 161
  • 189
36

If you are using Netbeans IDE then set the following -:

Config: -> BuildConfig.groovy: -> grails.server.port.http = 8090 and restart the server.

Without IDE, type in the command prompt -:

grails -Dserver.port 8090 run-app

or

grails -Dserver.port=8090 run-app
PritishC
  • 508
  • 8
  • 18
Gautam
  • 1,668
  • 18
  • 17
  • 1
    Very informative and tells every way to do this. Thanks gautam. – Chetan Aug 05 '14 at 07:31
  • @Gautam There was no field like grails.server.port.http in my BuildConfig, so I manually added it and tried but it gave response like 8080 in use(I was using it to deploy using tomcat). What could be the problem I have made. I have put grails.server.port.http = 8090 at the very beginning of BuildConfig – padippist Apr 04 '16 at 06:41
  • Try to kill all port of 80 and then try. For linux use '' sudo fuser -n tcp -k 80 '' or ' lsof -t -i:8080 ' in terminal – Gautam May 09 '17 at 11:12
21

For grails 3 you can put this in your application.yml

server:
    port: 9999
WizardsOfWor
  • 2,974
  • 29
  • 23
12

command line: grails run-app -port 8090

Cad
  • 374
  • 3
  • 6
6

Run the command (Ctrl+Alt+g)

  1. Up to grails version 2.x : run-app -Dserver.port=8090
  2. For grails version 3.x : run-app --port=8090
Nitin Dhomse
  • 2,524
  • 1
  • 12
  • 24
ujjwol shrestha
  • 145
  • 1
  • 12
5

If you are using IntelliJ IDE then

From the application menu click Run >> Edit Configurations... >> VM options: -Dgrails.server.port.http=8180

Jason Heithoff
  • 508
  • 3
  • 10
5

grails run-app -Dserver.port=8090

Or use another port number

In Intellij: Ctrl+Alt+G (keyboard Generic); Cmd+Alt+G (keyboard Mac) and use only:

run-app -Dserver.port=8090

Samuel Seda
  • 2,814
  • 1
  • 24
  • 13
3

Add/Update the value of port from your application.yml (grails-app/conf/application.yml)

environments:
   development:
        server:
            port: "8090"

Or

server:
    port: "8090"
Mahfuz Ahmed
  • 721
  • 9
  • 23
1

Type following in the command line:

grails -Dserver.port=8090 run-app
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

You didn't say what IDE you are using. If you are using Netbeans you just right-click on the project name and choose Properties. From the General Settings Category, you can easily change the server port to whatever you like.

Universitas
  • 493
  • 2
  • 5
  • 21
0

You can run grails app using the following command on the terminal. default running port is 8080.

grails run-app -Dserver.port=9090

This will run the app on port 9090.

0

For Grails 4 required two settings

server:
   port: "8085"
grails:
   serverURL: http://localhost:8085

Second one will solve redirection issues

Or only for dev:

environments:
    development:
        server:
            port: "8085"
        grails:
            serverURL: http://localhost:8085
demon101
  • 544
  • 1
  • 11
  • 39