Some code may be reused in various environments including Java EE Application server. Sometimes it is nice to know whether the code is running under application server and which application server is it.
I prefer to do it by checking some system property typical for the application server. For example it may be
jboss.server.name
for JBosscatalina.base
for Tomcat
Does somebody know appropriate property name for other servers? Weblogic, Websphere, Oracle IAS, others?
It is very easy to check if you have the specific application server installed. Just add line System.getProperties() to any JSP, Servlet, EJB and print the result.
I can do it myself but it will take a lot of time to install server and make it working.
I have read this discussion: How to determine type of Application Server an application is running on?
But I prefer to use system property. It is easier and absolutely portable solution. The code does not depend on any other API like Servlet, EJBContext or JMX.