11

How to change the default port from 9000 to 9001 in Play 2.5.9?

Tried following steps

  1. Changed http.port = 9001 in application.conf
  2. Tried the steps mentioned in this post [a link] How to change the http port for play framework 2.4.1?

But this works activator run -Dhttp.port=9001 -Dhttp.address=127.0.0.1

Can we change it from application.conf instead of specifying port from command line?

Community
  • 1
  • 1
Sheshank Kodam
  • 515
  • 5
  • 17

3 Answers3

15

In a way, no you can not add HTTP server setting in application.conf in reload mode (activator run).

In run mode by the time the play server starts, your application.conf is not resolved yet, but if you use state it works fine.

If you want to avoid providing port everytime you run the command, you could add it in build.sbt as following.

PlayKeys.devSettings := Seq("play.server.http.port" -> "9001")

It is explained here

RP-
  • 5,827
  • 2
  • 27
  • 46
6

Since version 2.5 you can set the port of your Play application in application.conf but this settings will only be used when running the application in production mode.

play.server {

    # These settings only apply when running in production mode (e.g. when using the stage/dist task)
    # To apply these settings in dev mode see:
    # https://www.playframework.com/documentation/2.5.x/ConfigFile#Using-with-the-run-command
    # https://groups.google.com/d/msg/play-framework/-EE28jmb4Uw/MBRQvAhhCwAJ
    # https://www.playframework.com/documentation/2.5.x/ProductionConfiguration
    # ~~~~~
    http {
        address = 127.0.0.1
        port = 9000
    }

    #https {
    #   address = 127.0.0.1
    #   port = 9000
    #}

}

To set the port in dev mode you have to stick with the setting in build.sbt RP- postet.

Community
  • 1
  • 1
mkurz
  • 2,658
  • 1
  • 23
  • 35
6

Latest play version(2.6.x) with sbt,you can also use

sbt "run 9001"
allwan
  • 61
  • 1
  • 3