【问题标题】:How can an application tell if its running on IBM WebSphere Application Server or IBM WebSphere Liberty Profile?应用程序如何判断它是在 IBM WebSphere Application Server 还是 IBM WebSphere Liberty Profile 上运行?
【发布时间】:2017-01-21 09:02:46
【问题描述】:

我正在处理一个应用程序,该应用程序需要知道它是在 WAS 上运行还是在 Liberty Profile 上运行。

在 WAS 上,它必须调用 Admin API,但在 Liberty Profile 上,它必须使用 JNDI 来做同样的事情。

【问题讨论】:

    标签: websphere websphere-liberty


    【解决方案1】:

    应用程序判断它是否在 Liberty 上运行的一种方法是搜索以下 MBean:WebSphere:name=com.ibm.ws.config.mbeans.FeatureListMBean

    这里是all MBeans provided in Liberty的列表

    下面是一个关于如何查询 MBean 的代码示例:

    private boolean isLiberty() throws Exception {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName obn = new ObjectName("WebSphere:name=com.ibm.websphere.config.mbeans.FeatureListMBean");
        Set<ObjectInstance> s = mbs.queryMBeans(obn, null);
        return s.size() > 0;
    }
    

    【讨论】:

    • 唯一的问题是它会引导 JMX 堆栈,这可能很慢。另一种方法是尝试加载 MBean 接口类,它们只会在 Liberty 中。
    猜你喜欢
    • 2015-12-19
    • 2018-07-07
    • 1970-01-01
    • 2014-12-06
    • 2018-08-18
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多