• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I externally specify the application's environment type?  RSS feed

 
Kev Adams
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I want to include code in my JEE application to display "Production", "Test", or "QA" depending on the server it's installed on, what is the best way to do that?

Can I use JNDI to look up a value on the server? If so, where would that go?

Any help would be appreciated.
 
Vladimir Ozerov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare the corresponding property (e.g. "env.type")within the application server. Then access it through System.getProperty("env.type").
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's common practice to use system properties via command line to specify the environment.
You would have a system property called "env" for example and then use it in the java command line that starts your application server.

The server on the QA environment will be started with : java -Denv=QA
The server on the Production environment will be started with : java -Denv=Production
etc

And in the java code you can pick up this value with
String currentEnv = System.getProperty("env");
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!