我想在我的网络应用程序中访问 Server
和 Connector
。 此外,我还需要从嵌入的Tomcat 启动这个网络应用程序。 下面是我如何启动Tomcat:
Tomcat tomcat = new Tomcat();
tomcat.setPort(port);
StandardServer server = (StandardServer) tomcat.getServer();
server.addLifecycleListener(new AprLifecycleListener());
tomcat.addWebapp("/", webapp.getAbsolutePath());
tomcat.start();
tomcat.getServer().await();
import javax.management.*;
import org.apache.catalina.Server;
MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
ObjectName name = new ObjectName("Catalina", "type", "Server");
Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
我理解: 我理解: I get: I get::
Caused by: javax.management.InstanceNotFoundException: Catalina:type=Server
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
我猜是因为我不知怎的 没能成功诱杀JMX