【问题标题】:Change default port number Play Framework : Using the SBT assembly plugin deployment option更改默认端口号 Play Framework:使用 SBT 程序集插件部署选项
【发布时间】:2016-04-20 13:53:08
【问题描述】:

我已经找到How do I change the default port (9000) that Play uses when I execute the "run" command?

但它没有答案。

这是特定于https://www.playframework.com/documentation/2.5.x/Deploying#Using-the-SBT-assembly-plugin

使用程序集部署选项时如何更改端口?

我正在使用

proc = new ProcessBuilder(

  "java",

  "-jar",

  "./lib/mode-assembley.jar",

  "-Dhttp.port=1234",

  "-Dplay.crypto.secret=abcdefghijk"



  ).start();

但这仍在尝试 9000 !并得到 ​​p>

错误的根服务器路径: /Users/xxxx/project/-Dhttp.port=1234

【问题讨论】:

    标签: playframework


    【解决方案1】:

    我认为你最好用 java 参数运行你的 jar

    java -jar ... -Dhttp.port=1234
    

    或者(也是我的首选方法),在每个环境中使用不同的配置文件。

    所以,在开发模式下你运行:

    sbt -Dconfig.resource=application.dev.conf run
    

    在文件conf/application.dev.conf 中有你想要的开发模式的所有配置。然后在conf/application.conf就可以进行生产配置了。

    请记住,您可以编写这些文件。所以,写成这样:

    conf/application.conf

    # the assembly command will take this one.
    http.port=9000
    

    conf/application.dev.conf

    include "application.conf"
    
    #override configuration parameters here for dev mode.
    http.port=1234
    

    这样,当你组装的时候,你就不用担心了,因为它默认使用conf/application.conf文件,除非你启动带有参数的jar,否则另一个将被忽略。

    java -jar -Dconfig.resource=application.dev.conf
    

    或者终于用java参数覆盖任何东西

    java -jar -Dconfig.resource=application.dev.conf -Dhttp.port=4321
    

    最后一个,将使用开发模式配置启动应用程序并覆盖端口。

    【讨论】:

    • 剧中application.conf需要加play.server.http.port
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 1970-01-01
    • 2021-07-31
    • 2016-07-28
    相关资源
    最近更新 更多