是否可以在嵌入式Tomcat7中启用JMX?

是否可以在嵌入式Tomcat7中启用JMX?,tomcat,tomcat7,jmx,Tomcat,Tomcat7,Jmx,我想从我的webapp中访问服务器和连接器s。此外,我需要从嵌入式Tomcat启动这个webapp。下面是我如何引导tomcat的: Tomcat tomcat = new Tomcat(); tomcat.setPort(port); StandardServer server = (StandardServer) tomcat.getServer(); server.addLifecycleListener(new AprLifecycleListener()); tomcat.addWeb

我想从我的webapp中访问
服务器
连接器
s。此外,我需要从嵌入式Tomcat启动这个webapp。下面是我如何引导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();
当我使用通过JMX访问服务器时:

我得到:

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。

看起来JMX运行良好,问题在于我用于查找的名称。应该是:

ObjectName name = new ObjectName("Tomcat", "type", "Server");

相反。

可以使用
PR\u JVM选项。我通过在嵌入式tomcat安装服务文件中使用以下配置参数解决了这个问题

set PR_JVMOPTIONS=-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false;-Dcom.sun.management.jmxremote.port=9111
set PR_JVMOPTIONS=-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false;-Dcom.sun.management.jmxremote.port=9111