Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify config file with sbt start in Play application?

I have what I assume to be a common use case for developing and deploying a Play 2.3.6 application:

  • In development, I run sbt run and the application uses application.conf as expected.
  • In production I would like to use sbt start and specify the config file, production.conf, which resides in the same directory as the dev config file (which is <project root>/conf/)

Following the instructions under the "Specifying alternative configuration file" heading on the official docs page, like so:

$ sbt start -Dconfig.file=/full/path/to/project/conf/production.conf

The application starts without error, but I can inspect the web application and see that it is loading my application.conf development values, not my production values found in production.conf.

I also tried the suggested approach:

$ sbt start -Dconfig.resource=production.conf

And the server fails to start with error:

[error] com.typesafe.config.ConfigException$IO: production.conf: java.io.IOException: resource not found on classpath: production.conf

Has anyone else figured out how to do this correctly?

like image 389
mjswensen Avatar asked Feb 11 '15 05:02

mjswensen


People also ask

How do I play .conf files?

If you need to open a CONF file, you can use TextMate in macOS or GNU Emacs in Linux. Some examples of configuration files include rc. conf for the system startup, syslog. conf for system logging, smb.

What is application conf file?

An application configuration file is an XML file used to control assembly binding. It can redirect an application from using one version of a side-by-side assembly to another version of the same assembly. This is called per-application configuration.

How do I use Typesafe config?

Creating a Typesafe Config With Fallbacks In this case, we first load our overrides. conf , then set a fallback of our defaults. conf from above. When searching for any property, it will first search the original config, then traverse down the fallbacks until a value is found.

What is ConfigFactory in Scala?

Configurations from a file By default, the ConfigFactory looks for a configuration file called application. conf. If willing to use a different configuration file (e.g.: another. conf), we just need to indicate a different file name and path to load (e.g.: ConfigFactory.


1 Answers

After a few wasted hours, I figured it out. Using quotes as follows passes the parameter correctly:

$ sbt "start -Dconfig.resource=production.conf"

Also, if you need to specify the port number, make sure it comes after the config option, otherwise it will be ignored:

$ sbt "start -Dconfig.resource=production.conf 9001"
like image 137
mjswensen Avatar answered Sep 22 '22 09:09

mjswensen