4

I have a project with the following configuration

  • Commons.conf
  • Application.conf for development
  • Production.conf for production

Both 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?

jacks
  • 4,614
  • 24
  • 34
emmea90
  • 357
  • 4
  • 10
  • "I cannot launch the application on command line because i did want it to be done automatically" - Can you define what "automatically" is? – The_Tourist Dec 06 '16 at 15:09
  • Double click on the bat script that automatically launch the JVM. The only way to pass parameters to JVM seems to be to edit the .bat itself on line 127 adding it after `set _JAVA_OPTS=!_JAVA_OPTS! !_JAVA_PARAMS!` – emmea90 Dec 06 '16 at 15:11
  • You need to look into how to execute the bat file on the command line - it is much better practice for you since you will likely have to deploy to a remote machine at some point in your career (whether it be windows or *nix) and will need to use the command line. – jacks Dec 06 '16 at 15:32

4 Answers4

10

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).

Specifying an alternative config file (couple of options)

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

An alternative approach (inheriting and overriding application.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.

More

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.

jacks
  • 4,614
  • 24
  • 34
2

You can do it two ways:

  1. If your package contains the configuration files:

$ <path_to_your_executable_file> -Dconfig.resource=<name_of_your_conf_file>

This will search for the configuration file in the application classpath, and and all such files should be in the conf directory before packaging.

  1. If you want to provide a completely alternate file which is not packaged with the application:

$ <path_to_your_executable_file> -Dconfig.file=<path_to_your_conf_file>

If you look at the contents of the zip file, you'll see bin and conf directories. bin contains the executables and conf contains the configuration files. So note that the configuration files are packaged separately.

The_Tourist
  • 2,048
  • 17
  • 21
1

In Play Framework 2.5.x you can run the project with the sbt command specifying the configuration file:

$ sbt '; set javaOptions += "-Dconfig.file=conf/integration.conf"; run'

You can launch the tests:

$ sbt '; set javaOptions += "-Dconfig.file=conf/integration.conf"; test'

Or use testOnly:

$ sbt '; set javaOptions += "-Dconfig.file=conf/integration.conf"; testOnly Integration*'

0

If you are using activator then use: activator run -Dconfig.file=conf/auxiliary.conf

If you are using sbt then use: sbt '; set javaOptions += "-Dconfig.file=conf/auxiliary.conf"; run'

Harsh Vardhan
  • 111
  • 1
  • 4