Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework Scala Environment Variables not found

Sup,

I'm trying to setup environment variables for my project in Play2.4 Scala. I have set variables in run configuration in Intellij.

What's annoying Scala doesn't seem to see those.

I keep getting errors of configuration not specified for keys I used env variables.

enter image description here

bug1

bug2

When i start the application those shows in the console:

"C:\Program Files\Java\jdk1.8.0_25\bin\java" -Dfile.encoding=UTF8 -DMAIL_PORT=587 -DDB_URI=mongodb://uri -Djline.terminal=none -Dsbt.log.noformat=true -Dsbt.global.base=C:\Users\Haito\AppData\Local\Temp\sbt-global-plugin7stub -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M -classpath C:\Users\Haito\.IntelliJIdea14\config\plugins\Scala\launcher\sbt-launch.jar xsbt.boot.Boot "project root" ~run

And the configuration file:

mongodb.uri = ${?DB_URI}

play.mailer {
  host=${?MAIL_HOST}
  port=${?MAIL_PORT}
  ssl=false
  tls=true
  user=${?MAIL_USERNAME}
  password=${?MAIL_PASSWD}
  debug=false
  mock=false
}

And i keep getting those:

Missing configuration key 'mongodb.db'!

Of course my problem is not that my mongo driver. My problem is that the config is not being fed with environment variables. Mailer which also uses environment variables for configs. When I paste the actual URI except the ${?DB_URI} it works.

Build:

resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"

resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"

libraryDependencies ++= Seq(
  "org.reactivemongo" %% "play2-reactivemongo" % "0.11.2.play24"
)

libraryDependencies ++= Seq(
  "com.typesafe.play" %% "play-mailer" % "3.0.1"
)
like image 520
Haito Avatar asked Oct 24 '15 10:10

Haito


1 Answers

This is a bug in IntelliJ. Setting the "Environment variables" field in the Play run configuration sets system properties, not environment variables.

If you configure environment variables manually somewhere like .bash_profile then you can certainly use them in your application.conf like:

db.default.url = ${?DB_URL}
like image 139
David Keen Avatar answered Sep 22 '22 02:09

David Keen