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

3 Answers 3

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 
Sign up to request clarification or add additional context in comments.

1 Comment

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.
5

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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.