Currently using playframework 2.0.2 and in my application.conf i set the db connection info
db.default.url="jdbc:mysql://localhost:3306/test"
db.default.driver=com.mysql.jdbc.Driver
db.default.user=test
db.default.pass=test
But what I would like to know is when i put my application into production using "play clean update dist" and then install it on site there is no application.conf. This means that I have to change the db connection before I distribute the code? is there a way to change the db connection in a config file after you have distributed it?
When you use play dist
the config files get packaged into a jar file in the zip. You could create a conf/prod.conf
file containing something like:
include "application.conf"
db.default.url="jdbc:mysql://foo.com:3306/mydb"
db.default.driver=com.mysql.jdbc.Driver
db.default.user=foo
db.default.pass=bar
Then when you start the Play app tell it to use the prod.conf
file by running:
start -Dconfig.resource=prod.conf
To avoid packaging the config file at all I would suggest that you create a prod.conf on the production servers and store in a folder other than folder you unzip the distributed files to. Then create a startup script like below (or a more sophisticated startup script that start your app as a service). By keeping the config file separate from you dist package you avoid the risk of accidentally overriding it when pushing out new changes.
#!/bin/bash
sh start -Dconfig.file=/path/to/prod.conf &
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