简体   繁体   中英

Determine Which Application Server our application is deployed to?

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.

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 (eg org.jboss.Version in JBoss 4). If it exists, you know what server you're on.

您可以通过ServletContext#getServerInfo()找到它。

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 .

更改为System.getProperty("jboss.home.dir")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM