【问题标题】:Build Scala Play app using different config file使用不同的配置文件构建 Scala Play 应用程序
【发布时间】:2021-01-11 19:39:35
【问题描述】:

我有一个使用 sbt 构建的 Scala Play 应用程序。

当我使用sbt dist 命令构建包时,这将导致在/target/universal 路径中部署一个存档。问题是我有 3 个配置文件:

  • application.conf
  • dev.conf
  • prod.conf

如果我尝试运行sbt dist -Dconfig.resource=prod.conf,我会收到错误:

[error] Expected ID character
[error] Not a valid command: prod (similar: stopProd, runProd, reload)
[error] Expected project ID
[error] Expected configuration
[error] Expected ':' (if selecting a configuration)
[error] Expected key
[error] Not a valid key: prod (similar: products, projectId, project-id)
[error] prod.conf

即使我使用引号或-Dconfig.file,结果也是一样的。我哪里错了?谢谢

后期编辑:

sbt dist 将构建 bin/*.bat 文件,但其余文件将保持未构建状态。所以,我想如果我选择这个.zip 解决方案,所有环境类型(dev、stage、prod)的包都是相同的,但是我可以在运行命令启动应用程序时选择配置文件:

例如,对于 prod,我可以使用:

nohup ./app-name-1.0/bin/app-name -J-Xms8g -J-Xmx8g -Dconfig.resource=prod.conf -Dhttp.port=7777</dev/null>> logfile.log 2>&1 &

-Dconfig.resource=prod.conf 在此帖子中制作我想要的内容。

【问题讨论】:

标签: scala build playframework sbt


【解决方案1】:

dist 命令不接受配置参数,因此您收到错误不是有效的命令。 您可以使用系统属性来指定配置文件https://www.playframework.com/documentation/2.8.x/ConfigFile。 这允许您为生产环境加载不同的文件

【讨论】:

    【解决方案2】:

    scala-sbt.org 上找到sbt-native-packager 的教程,但出现奇怪的错误。

    目前,对构建为.bat 文件的sbt 项目使用不同配置文件的唯一解决方案是指定启动命令的配置文件,我在上面指定的方式(-Dconfig.resource=prod.conf):

    nohup ./path -J-Xms8g -J-Xmx8g -Dconfig.resource=prod.conf -Dhttp.port=7777</dev/null>>
    

    所以,第一步是使用sbt dist 创建压缩包,无需考虑配置文件。然后,在服务器上解压文件,并使用命令启动应用程序。

    【讨论】:

      猜你喜欢
      • 2014-09-16
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-30
      • 1970-01-01
      • 2015-10-08
      相关资源
      最近更新 更多