使用JMX编写PMI应用问题

想尝试写个WebSphere应用监控的小东东,就照着文档下载Sample试了试(具体参见:Writing PMI applications using the JMX interface),呵呵,碰到不少问题,还好解决了。看Googel上也有人问,就拿出来共享一把了。

1、找不到相关类
报错:java.lang.ClassNotFoundException,或者:java.lang.NoClassDefFoundError,这就需要检查相关的运行期环境了。
首先从Java Stack Trace信息中明确无法找到的类,如下报错:
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/websphere/product/WASProduct
    at com.ibm.ws.management.util.Utils.getProductVersion(Utils.java:106)
    at com.ibm.ws.management.connector.interop.JMXVersionValidation.getJmxVersionHeader(JMXVersionValidation.java:95)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient.invokeTemplate(SOAPConnectorClient.java:582)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient.queryNames(SOAPConnectorClient.java:438)
    at com.ibm.ws.management.connector.soap.SOAPConnectorClient.invoke(SOAPConnectorClient.java:370)
    at $Proxy0.queryNames(Unknown Source)
    at com.ibm.ws.management.AdminClientImpl.queryNames(AdminClientImpl.java:89)
    at com.ibm.websphere.pmitool.JmxStat.queryObjectNames(JmxStat.java:321)
    at com.ibm.websphere.pmitool.JmxStat.listNodes(JmxStat.java:341)
    at com.ibm.websphere.pmitool.JmxStat.main(JmxStat.java:70)
可确认com.ibm.websphere.product.WASProduct类无法找到。
由于WebSphere本身可以正常获取PMI信息,所以可以确定这些类在WebSphere生产环境下必然存在,而开发环境中并未引入这些类从而导致找不到类的错误。那就在生产环境中找找了,看漏了哪些jar包。
如何从生产环境中找到相应jar包呢,呵呵,感谢那些Unix Power Tools了,Window上我还真不知道怎么办了。具体命令和输出如下:
# cd $WAS_HOME/lib
# class="com.ibm.websphere.product.WASProduct"
# find . ! -name . -prune -name "*.jar" -exec jar tvf {} \; -print | egrep "$class|.jar" | sed -n "/$class/{
> :top
> N
> /\.jar/p
> /\.jar/q
> b top
> }"
 11886 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_de.class
 12249 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_es.class
 12215 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_fr.class
 12038 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_it.class
 13175 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_ja.class
 11856 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_ko.class
 11833 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_pt_BR.class
 10359 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_zh.class
 10539 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_zh_TW.class
 11091 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS.class
 11097 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_en.class
 11097 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductNLS_pt.class
 23110 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProduct.class
  1720 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductException.class
  1830 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductInfo.class
  4897 Wed Jul 04 14:34:10 GMT+08:00 2007 com/ibm/websphere/product/WASProductFile.class
./wasproduct.jar
呵呵,找到wasproduct.jar,加入到开发环境中就好了。

2、类转换错误
由于Sample代码针对WebSphere5,而我的WebSphere版本6.0,故执行中常碰到:java.lang.ClassCastException异常。
如下语句:
            return(Stats)ac.invoke(perfOname, "getStatsObject", params, sigs);
执行中将报错:
java.lang.ClassCastException: com.ibm.ws.pmi.stat.StatsImpl
    at com.ibm.websphere.pmitool.JmxStat.collectStatsViaPerfMbean(JmxStat.java:818)
    at com.ibm.websphere.pmitool.JmxStat.main(JmxStat.java:194)
检查发现ac.invoke返回类com.ibm.ws.pmi.stat.StatsImpl,该类无法转换为com.ibm.websphere.management.statistics.Stats,事实上该类实现了com.ibm.websphere.pmi.stat.WSStats,故需要将Sample代码做出相应的修改:
            return(WSStats)ac.invoke(perfOname, "getStatsObject", params, sigs);
呵呵,由于版本不兼容的类似修改就多了,只能case by case的去解决了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值