The answer is NO. It is not possible to determine whether your code will work in any application server container / servlet or autonomously without relying on external information.
However, you can specify a system property in one case and not another, and verify its existence:
java -Dstandalone.mode=true MyApplication
In your code:
if (Boolean.getBoolean("standalone.mode")) {
}
source
share