I have a project with the following configuration
Commons.confApplication.conf for developmentProduction.conf for productionBoth application.conf and production.conf include commons.conf
I have to build the application using dist task to generate the zip file, then start it using the projectname.bat file provided.
I added javaOptions ++= Seq("-Dconfig.file=conf/production.conf") in build.sbt but it seem that did not working. I cannot launch the application on command line because i did want it to be done automatically. What's the better way to do separate .conf file configuration for development and production and have dist task taking the production ones?
On startup of your application, Play is automatically configured to load application.conf from the classpath. To override this with an alternative you need to specify this on startup.
Note that whether you are deploying to Windows and starting the app with a .bat, or Linux with a .sh you are usually executing that file as follows:-
$ target/universal/stage/bin/<project-name>
The above will execute your .bat file (if you are on Microsoft that is).
So if you want to have separate configuration files for prod/dev then use the default application.conf for dev and use a production.conf for prod.
If you put application.conf inside conf then you would specify it as follows:-
$ /path/to/bin/<project-name> -Dconfig.resource=production.conf
If application.conf is not packaged with your app (ie. you have not put it in conf then you need to specify full path using.
$ target/universal/stage/bin/<project-name> -Dconfig.file=/full/path/to/conf/production.conf
Include application.conf in prod.conf and just override what you need to for prod
Note that you can include configuration inside another, so what I usually do is specify a prod.conf like this:-
include "application.conf"
key.to.override=blah
Then specify prod.conf when you start the app and application.conf will automatically be included. You can then just specify the properties in prod.conf that override those in application.conf for your production environment.
Not that you can also use system properties and environment variables to override settings in application.conf. I encourage you to take some time to read the docs to understand the options more fully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With