Our J2EE Application is deployed to JBoss and sometimes to OC4J . Can I know which one is being used? I hope there is a method returning the container information on runtime.
A:
Most likely JMX is what you are going to need to use. Both containers likely expose details about themselves as MBeans. Here is some Oracle documentation on JMX and JBoss documentation.
John Paulett
2009-11-17 00:34:53
+3
A:
Simplest thing I can think of is to look through the system properties at runtime, since both servers are almost certainly going to define their own. For example, JBoss 4 defines the jboss.server.dir
system property. Check to see if that property exists, and if it does, then you can assume you're running under that server. OC4J will have something similar.
Alternatively, try reflectively loading a class that is part of the server's infrastructure (e.g. org.jboss.Version
in JBoss 4). If it exists, you know what server you're on.
skaffman
2009-11-17 08:25:45
Curious... I suspect that'll return the name of the servlet container, rather than the app server, but it may be enough.
skaffman
2009-11-23 21:16:37
Depends on the appserver. For example JBoss 4.2.x and newer do return "JBoss", but the older versions used to return "Apache Tomcat".
BalusC
2009-11-23 22:39:01