Determine which application server our application applies to?

The J2EE application is deployed for JBoss, and sometimes for OC4J. Can I find out which one is being used? I hope there is a method that returns container information at runtime.

+4
source share
4 answers

The simplest thing I can think of is to check the properties of the system at runtime, since both servers will almost certainly determine their own. For example, JBoss 4 defines the system property jboss.server.dir . Check if this property exists, and if so, then you can assume that you are working under this server. OC4J will have something similar.

Alternatively, try reflecting the loading of a class that is part of the server infrastructure (e.g. org.jboss.Version in JBoss 4). If it exists, you know which server you are on.

+3
source

You can find this at ServletContext#getServerInfo() .

+2
source

Most likely, JMX is what you will need to use. Both containers probably reveal details about themselves as MBeans. Here are some Oracle JMX documentation and JBoss documentation .

0
source

Change to System.getProperty("jboss.home.dir")

0
source

All Articles