更改默认播放框架HTTP端口(不使用系统属性)

时间:2016-04-08 17:17:39

标签: scala playframework sbt

关于更改Play应用程序将绑定的HTTP端口,有一个常见问题。 James Ward's answer通常被认为是最完整的,但它涉及通过设置http.port系统属性来覆盖默认值。但是,是否可以更改此默认值而无需在开发时手动将其添加到run命令,调整环境或在运行时配置中打包覆盖?

1 个答案:

答案 0 :(得分:1)

这可以通过设置playDefaultPort key来完成,如下所示:

import PlayKeys._
playDefaultPort := 9123

之后,您将能够runtestProd而无需记住所需的端口。

这适用于两种开发:

$ sbt run
[info] Loading project definition from /Users/michaelahlers/Projects/MyApp/project
[info] Set current project to MyApp (in build file:/Users/michaelahlers/Projects/MyApp/)

--- (Running the application, auto-reloading is enabled) ---

[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9123

(Server started, use Ctrl+D to stop and go back to the console...)

生产模式:

$ sbt testProd
[info] Loading project definition from /Users/michaelahlers/Projects/MyApp/project
[info] Set current project to MyApp (in build file:/Users/michaelahlers/Projects/MyApp/)
[info] Packaging /Users/michaelahlers/Projects/MyApp/target/scala-2.11/MyApp_2.11-1.0.0-SNAPSHOT-web-assets.jar ...
[info] Done packaging.

(Starting server. Type Ctrl+D to exit logs, the server will remain in background)

2016-04-08 13:09:45,594 [info] a.e.s.Slf4jLogger - Slf4jLogger started
2016-04-08 13:09:45,655 [info] play.api.Play - Application started (Prod)
2016-04-08 13:09:45,767 [info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9123