获取tomcat配置的端口
/** * 根据协议和scheme获取服务端口号 * @return 端口号 */ private static String getHttpPort(String protocol, String scheme) { MBeanServer mBeanServer = null; if (MBeanServerFactory.findMBeanServer(null).size() > 0) { mBeanServer = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0); } Set names = null; try { names = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,*"), null); } catch (Exception e) { return ""; } Iterator it = names.iterator(); ObjectName oname = null; while (it.hasNext()) { oname = (ObjectName)it.next(); String pvalue = (String)mBeanServer.getAttribute(oname, "protocol"); String svalue = (String)mBeanServer.getAttribute(oname, "scheme"); if (protocol.equals(pvalue) && scheme.equals(svalue)) { return ((Integer)mBeanServer.getAttribute(oname, "port")).toString(); } } } return ""; }