[英]Determine Which Application Server our application is deployed to?
Our J2EE Application is deployed to JBoss and sometimes to OC4J . 我们的J2EE应用程序部署到JBoss,有时部署到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. 例如,JBoss 4定义了jboss.server.dir
系统属性。 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. OC4J会有类似的东西。
Alternatively, try reflectively loading a class that is part of the server's infrastructure (eg org.jboss.Version
in JBoss 4). 或者,尝试反射性地加载属于服务器基础结构的类(例如JBoss 4中的org.jboss.Version
)。 If it exists, you know what server you're on. 如果存在,您就知道您所在的服务器。
您可以通过ServletContext#getServerInfo()
找到它。
Most likely JMX is what you are going to need to use. 最有可能JMX是您需要使用的。 Both containers likely expose details about themselves as MBeans. 两个容器都可能将自己的详细信息公开为MBean。 Here is some Oracle documentation on JMX and JBoss documentation . 以下是有关JMX和JBoss文档的一些Oracle 文档 。
更改为System.getProperty("jboss.home.dir")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.