Playframework: Unable to access environment variables within application.conf

Created on 12 Oct 2016  ·  3Comments  ·  Source: playframework/playframework

Play Version (2.5.x / etc)

2.5.x

API (Scala / Java / Neither / Both)

Java

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

Ubuntu 15.10

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

Oracle 1.8.0_72

Expected Behavior

  1. Distributable created from 'activator clean compile dist'
  2. The zip file is extracted and the binary file of the application in /bin folder is executed.
  3. The configuration parameters given in the application.conf is loaded from the environment variables as documented here: https://www.google.com/url?q=https%3A%2F%2Fwww.playframework.com%2Fdocumentation%2F2.5.x%2FProductionConfiguration&sa=D&sntz=1&usg=AFQjCNFhDiYsiRReBQBHZNL6Pzs_jGnkVQ

    Actual Behavior

  4. Distributable created from 'activator clean compile dist'

  5. The zip file is extracted and the binary file of the application in /bin folder is executed.
  6. The configuration parameters given in the application.conf is NOT loaded from the environment variables. The configuration parameters are set to null.

    PS

We have posted this in google groups(https://groups.google.com/forum/#!topic/play-framework/9THTrrw6YO8) and stack-overflow, but have not received any answers so far.

Most helpful comment

I ran a quick test using our play-scala example to attempt to confirm this:

I modified application.conf to contain:

play.crypto.secret = ${?PLAY_SECRET}

(so I know the app will fail to start if the environment variable is not defined)

sbt dist
unzip target/universal/play-scala-1.0-SNAPSHOT.zip
cd play-scala-1.0-SNAPSHOT/bin
./play-scala # produces configuration error as expected
PLAY_SECRET=foobar ./play-scala # works fine

So I'm unable to reproduce. I suspect you're just not setting the environment variable properly.

All 3 comments

I ran a quick test using our play-scala example to attempt to confirm this:

I modified application.conf to contain:

play.crypto.secret = ${?PLAY_SECRET}

(so I know the app will fail to start if the environment variable is not defined)

sbt dist
unzip target/universal/play-scala-1.0-SNAPSHOT.zip
cd play-scala-1.0-SNAPSHOT/bin
./play-scala # produces configuration error as expected
PLAY_SECRET=foobar ./play-scala # works fine

So I'm unable to reproduce. I suspect you're just not setting the environment variable properly.

@gmethvin I am setting environment variables through source command in shell. When I echo the variable( example: echo $PLAY_SECRET) in the shell, I am seeing the correct value.
Can you let me know how you are setting environment variable? I will share my sample soon.

@Technowise You can export

export PLAY_SECRET=foobar
./play-scala

or set the environment variable for just one command:

PLAY_SECRET=foobar ./play-scala

I know bash and zsh support those syntaxes, and csh uses setenv. You'll have to check that you're using the correct syntax for whichever shell you use.

Was this page helpful?
0 / 5 - 0 ratings