I want to specify port on which Java Play exposes its endpoints in the application.conf
file – complete snippet of the application.conf
, format taken from Java Play documentation
play.server.http.port = 5511
However, if I run command
sbt run
exposed port is 9000, not 5511.
I was able to achieve correct behaviour by running
sbt run -Dhttp.port=5511
so there must be problem in the application.conf
.
If I try to read the value programmatically, say from controller, it also gets the wrong value of 9000. However, if I add some artificial value to the application.conf
, say foo = "ABC"
, it correctly reads this value.
As per of the play documentation :
In run mode the HTTP server part of Play starts before the application has been compiled. This means that the HTTP server cannot access the application.conf file when it starts. If you want to override HTTP server settings while using the run command you cannot use the application.conf file
I would propose you do this way sbt run -Dhttp.port=5511
as you stated earlier. If you are worried about passing everytime the arguments with run task then you can change your root project settings in the build.sbt
file only once. Do not forget to to sbt reload
so your build.sbt
changes take effect.
lazy val root = (project in file(".")).enablePlugins(PlayJava)
.settings(PlayKeys.playDefaultPort := 5511)
Another alternative : you can add the following line in your build.sbt file
PlayKeys.devSettings += "play.server.http.port" -> "8080"