兄弟们,大老爷们,救火呀..weblogic jmx管理的程序..在线等
这几天要做一个weblogic jmx的服务的管理,把weblogic里的jmx从程序中抽出写成程序.
我从网上搜索了一些程序,但是报错.环境是这样的. eclipse3.3+weblogic 8.1+jdk1.4
weblogic.jar 和jbossall-client.jar 已经加到lib下
出错的信息是
weblogic.rmi.extensions.RemoteRuntimeException: Unexpected Exception - with nested exception:
[weblogic.rjvm.PeerGoneException: ; nested exception is:
weblogic.utils.NestedException: Lorg/jboss/mx/util/ObjectNamePatternHelper$PropertyPattern; - with nested exception:
[java.lang.NoClassDefFoundError: Lorg/jboss/mx/util/ObjectNamePatternHelper$PropertyPattern;]]
at weblogic.management.internal.AdminMBeanHomeImpl_811_WLStub.getActiveDomain(Unknown Source)
at com.ivsoftware.weblogic.WeblogicJMX.main(WeblogicJMX.java:32)
Exception in thread "main"
程序如下:
public class WeblogicJMX {
public MBeanHome localHome;
public MBeanHome adminHome;
public static final String SERVER_NAME = "weblogic";
public static final String SERVER_PASSWORD = "weblogic";
public static final String SERVER_URL = "t3://localhost:7001";
//public static final String SERVER_URL = "t3://158.222.30.246:7001";
public static final String SERVER_POOL="MyJDBCMultiPool";
// public static final String SERVER_POOL="MyPool";
public static void main(String[] args) {
WeblogicJMX weblogicJMX = new WeblogicJMX();
MBeanHome mBeanHome = weblogicJMX.getMBeanHome();
System.out.println(mBeanHome.getActiveDomain());
System.out.println("domainName:"+mBeanHome.getDomainName()+" serverName:"+mBeanHome.getMBeanServer());
//
// // In this case we want the 100 most recently executed statements
// JDBCStatementProfile[] profiles = weblogicJMX.getProfiles(100);
// // Doing the looping so that the most recent statements information is
// // retrieved first
// for (int i = profiles.length - 1; i > -1; i--) {
// // Getting the number of parameters passed into the current
// // //statement
// int paramCount = profiles[i].getParameterCount();
// // Format the start and end time for the current statement
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
// "yyyyy.MMMMM.dd GGG hh:mm:ss:SS aaa");
// String startTime = simpleDateFormat.format(new Date(profiles[i]
// .getStartTime()));
// String endTime = simpleDateFormat.format(new Date(profiles[i]
// .getStopTime()));
//
// // Append the parameters together in order to display them
// StringBuffer paramsBuffer = new StringBuffer();
// if (paramCount < 1) {
// paramsBuffer.append("None");
// } else {
// for (int j = 0; j < paramCount; j++) {
// paramsBuffer.append(profiles[i].getParameter(j));
// paramsBuffer.append(" ");
// }
// }
//
// String statementTxt = profiles[i].getStatementText();
// String paramsTxt = paramsBuffer.toString();
// long timeTaken = profiles[i].getTimeTaken();
//
// // Then use statementTxt, paramsTxt, timeTaken, startTime, endTime
// // etc to show the statement details in a UI
// }
}
private MBeanHome getMBeanHome() {
// URL to the serve whose JDBC activity we are tracing
// The MBeanHome will allow us to
// retrieve the MBeans related to JDBC statement tracing
MBeanHome home = null;
try { // We'll need the environment so that we can //retrieve the
// initial context
//--------------------
Environment env = new Environment();
env.setProviderUrl(SERVER_URL);
env.setSecurityPrincipal(SERVER_NAME);
env.setSecurityCredentials(SERVER_PASSWORD);
Context ctx = env.getInitialContext();
// Retrieving the MBeanHome interface for the server with //the url
// t3://localhost:7001
home = (MBeanHome) ctx.lookup(MBeanHome.ADMIN_JNDI_NAME);
//----------------------
// home = (MBeanHome)Helper.getMBeanHome("weblogic","weblogic",SERVER_URL,"myserver");
} catch (Exception ne) {
System.out.println("Error getting MBeanHome " + ne);
}
return home;
}
public void configureJDBCAuditing(boolean isOn) {
try {
MBeanHome home = getMBeanHome();
// Retreive the bean to help us configure the Pool
JDBCConnectionPoolMBean mConfigBean = (JDBCConnectionPoolMBean) home
.getConfigurationMBean(SERVER_POOL, "JDBCConnectionPoolConfig");
mConfigBean.setSqlStmtProfilingEnabled(isOn);
mConfigBean.setSqlStmtParamLoggingEnabled(isOn);
} catch (InvalidAttributeValueException iave) {
System.out.println("Invalid attribute while configuring tracing "
+ iave);
} catch (InstanceNotFoundException infe) {
System.out.println("Instance not found while configuring tracing "
+ infe);
}
}
/** Pass in -1 to get all profiles */
public JDBCStatementProfile[] getProfiles(int maxProfiles) {
JDBCStatementProfile[] profiles = null;
try {
MBeanHome home = getMBeanHome();
JDBCConnectionPoolRuntimeMBean mbean = (JDBCConnectionPoolRuntimeMBean) home
.getRuntimeMBean(SERVER_POOL, "JDBCConnectionPoolRuntime");
int numProfiles = mbean.getStatementProfileCount();
int profilesIndex = 0;
// figure out index to start at and how many we want
if (maxProfiles != -1) {
profilesIndex = numProfiles - maxProfiles;
} else {
maxProfiles = numProfiles;
}
profiles = mbean.getStatementProfiles(profilesIndex, maxProfiles);
} catch (InstanceNotFoundException infe) {
System.out.println("Problem retrieving jdbc profiles " + infe);
}
return profiles;
}
public void reset() {
MBeanHome home = getMBeanHome();
try {
JDBCConnectionPoolRuntimeMBean mbean = (JDBCConnectionPoolRuntimeMBean) home
.getRuntimeMBean(SERVER_POOL, "JDBCConnectionPoolRuntime");
// Remove everything from the cache
mbean.resetStatementProfile();
} catch (InstanceNotFoundException infe) {
System.out.println("Problem while resetting JDBC profiles " + infe);
}
}
}