30

I'd like to do this in Java Google App Engine

if(developmentMode)
  foo();
else
  bar();

Does anyone know a good way to do this?

Daniel

David Underhill
  • 15,896
  • 7
  • 53
  • 61
supercobra
  • 15,810
  • 9
  • 45
  • 51

3 Answers3

44

https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/utils/SystemProperty

In Java just test

SystemProperty.environment.value() == SystemProperty.Environment.Value.Production
Matthew Cline
  • 2,312
  • 1
  • 19
  • 36
Marc Hacker
  • 476
  • 5
  • 2
  • 8
    Minor note: The question asks how to check if we're on a *development* system but the test above checks if we're on a *production* system (i.e. the condition is negated). Change to `!=` or use `SystemProperty.Environment.Value.Development`. – Brian White Nov 22 '13 at 02:57
5

In Python, check the SERVER_SOFTWARE environment variable. It'll be "Development/X.Y" in development mode. In Java, ServletContext.getServerInfo().

Bob Aman
  • 32,839
  • 9
  • 71
  • 95
0

Take a look at this thread on the GAE/J Group.

Several techniques are listed there. You might also look at this blog entry

It suggests doing: ServletContext.getServerInfo()

"In development this will be 'Google App Engine Development/x.x.x' and in production it will be 'Google App Engine/x.x.x'"

This blog suggests writing a ServletContextListener to sniff this value so you can expose it to classes that don't have access to the ServletContext.

James Cooper
  • 2,320
  • 2
  • 23
  • 23