Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 3 - change default port for run-app

In Grails3 grails -Dserver.port=9001 run-app doesn't appear to work:

I'm "getting address already bound 8080".

Any idea how to do this - ideally by passing a property to "gradle run"?

like image 207
Neill Robbins Avatar asked Feb 09 '15 15:02

Neill Robbins


4 Answers

You can use

server:
  port: 9001

in application.yml.

Or you can pass it via system environment. (e.g. SERVER_PORT=9001 grails run-app).

like image 81
dmahapatro Avatar answered Nov 16 '22 15:11

dmahapatro


grails run-app --port=8081

Or in interactive mode:

run-app --port=8081

Don't forget to use the same port when you want to stop the server:

stop-app --port=8081

I believe this feature was broken in 3.0.3 and earlier versions but it definitely works in 3.0.4.

like image 26
and Avatar answered Nov 16 '22 16:11

and


Accepted answer is correct. For some additional info, Grails 3 uses spring-boot and the server properties are configured by the

org.springframework.boot.autoconfigure.web.ServerProperties

class. "port" is just a property on this class which is filled from the application.yml with the prefix "server". So in addition to the port, you can set properties of this class including tomcat configuration properties and etc. To change the contextPath for instance you add

server: 
   contextPath: /myapp

to you application.yml.

like image 4
Cagatay Kalan Avatar answered Nov 16 '22 16:11

Cagatay Kalan


  server:
  port: 9809
  contextPath: '/admin/'

you can use this in your application.yml file

or change the port depends on the environment for example :

    environments:
        test:
            grails:
                serverURL: "http://localhost:9809"
like image 3
rihabe berrich Avatar answered Nov 16 '22 17:11

rihabe berrich