How can one identify whether some code (a serv-let or a simple class) is running on Google App Engine run-time (Java) so that one can decide whether to utilize app engine's specific libraries or not? Is there some reliable runtime enviroment ID for that?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You can check the
com.google.appengine.runtime.version
property:If it's set, it's App Engine.
But I would consider using separate build targets instead, to avoid the runtime overhead.
I saw no type-safe solution here so here it is:
As explained here you can check the following property:
environment
is "Production" when running on App Engine, and "Development" when running in the development server.There is another way to do this as well. This is explained well in gaevfs's documentation on how to write Portable Code: http://code.google.com/p/gaevfs/wiki/ApplicationPortability
Of interest to you is the following line:
similar to what @Reza wrote, but a bit cleaner:
use
SystemProperty.environment.value()
to get "Production" when running on App Engine, and "Development" when running in the development server.As @Matthew Flaschen said, there are system properties that you can check to determine if GAE is present or not. This link gives the details.
If you go down this route, your application needs to be built so that the main code has no static dependencies on the GAE classes; i.e. no imports or other references to GAE packages and classes in the code (apart GAE class names, etc in String literals). All dependencies have to be isolated to code that gets loaded using
Class.forName(String)
AFTER you've determined whether or not GAE is present.This represents a non-trivial overhead:
On the other hand, you do have the potential advantage of having one JAR that works in both GAE and non-GAE contexts.