Scala – Dynamic Environment Selection

Command Line Arguments are passed to the Main Program

 

 

StartApp.scala

 

/**
* Created by Nag Arvind Gudiseva on 05-04-2016.
*/
object StartApp extends App {

 

val jobId: Int = args(0).toInt

println(“Job Id: ” + jobId)

 

val requester = args(1)

println(“Requester: ” + requester)

 

val env = args(2)

println(“Environment: ” + env)

 

println(“Parameter: ” + Config.param)

 

}

 

 

Config.scala

 

/**
* Created by Nag Arvind Gudiseva on 14-April-2016.
*/
object Config {

 

var environment: String = StartApp.env

/** Loads all key / value pairs from the application configuration file. */
var conf = ConfigFactory.load(“params_” + environment + “.conf”)

 

/** Seed locations for which URLs are valid, example ca, nj etc. */
lazy val param = conf.getString(“param”)

 

}

 

 

params_dev.conf

{

param=”DEVELOPMENT Parameter”
}

 

params_prd.conf

{

param=”PRODUCTION Parameter”
}

 

params_stg.conf

{

param=”STAGE Parameter”
}

 

params.conf

{

param=”Default Parameter”
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s