0

I have a Scala Play application builded using sbt.

When I build the package using sbt dist command, this will result in an archive deployed in /target/universal path. The problem is that I have 3 configuration files:

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

If I try to run sbt dist -Dconfig.resource=prod.conf, I get an error:

[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

Even if I use quotes, or -Dconfig.file, the result is the same. Where am I wrong? thanks

late edit:

sbt dist will build the bin/*.bat files, but the rest of files will remain unbuilded. So, I think if I go for this .zip solution, the package will be the same for all environment types (dev, stage, prod), but I can choose the config file when I run the command to start application:

for example, for prod I can use:

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 &

where -Dconfig.resource=prod.conf make what I want in this post.

AlleXyS
  • 2,476
  • 2
  • 17
  • 37
  • This may help a little https://stackoverflow.com/questions/40998441/play-how-to-use-different-configuration-files-for-dev-prod?answertab=votes#tab-top – jacks Sep 25 '20 at 23:15

2 Answers2

0

the dist command does not take a config argument , therefore you are receiving the error not a valid command. You can use a system property to specify a config file https://www.playframework.com/documentation/2.8.x/ConfigFile. This allows you to have a different file loaded for your production environment

YisraelU
  • 352
  • 1
  • 8
0

Found a tutorial on scala-sbt.org for sbt-native-packager, but got strange errors.

For moment, the only solution to use a different config file for a sbt project builded as .bat file is to specify the config file for starting command, how I specified above (-Dconfig.resource=prod.conf):

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

So, first step is to use sbt dist to create the zip package without matter about config file. Then, unzip the file on server, and use command to start the application.

AlleXyS
  • 2,476
  • 2
  • 17
  • 37