我有一个主程序作为com.yammer.dropwizard.Service的实例运行
SystemInformationService extends Service<SystemInformationConfiguration>
尝试以编程方式从远程进程停止Jetty服务。我曾尝试使用JMX消息传递服务,但是当我通过jconsole查看MBean时,没有看到可用的stop方法。代码我试过,但得到一个javax.management.InstanceNotFoundException:org.eclipse.jetty.server.Server:type = server,id = 0 exception is below
String JMX_URL = "service:jmx:rmi:///jndi/rmi://localhost:9095/jmxrmi";
System.out.println("Shutting down Jetty instance");
JMXConnector connector = JMXConnectorFactory.connect(new JMXServiceURL(JMX_URL), null);
connector.connect();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName on = new ObjectName("org.eclipse.jetty.server.Server:type=server,id=0");
connection.invoke(on, "stop", null, null);
System.out.println("Shutdown command sent");
return new AgentStatus(ApplicationStatus.OFFLINE);
另请注意,该服务是使用这些标志启动的
-Dcom.sun.management.jmxremote.port=9095 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false