Best way to detect whether code is running in an application server java
Make sure the server is started with
java -Djava.awt.headless=true
Most servers should be started that way by default. Then you can check:
boolean headless_check = GraphicsEnvironment.isHeadless();
More details on headless available here: