How do I find out what port my jboss server is lis

2019-02-02 15:18发布

问题:

For example, how do I determine that my simple JBoss 4.2.3 server is listening on port 8080?

This is the closest I have been able to come, but this doesn't work:

MBeanServerConnection server = (MBeanServerConnection)new InitialContext()
    .lookup("jmx/rmi/RMIAdaptor");
ObjectName on = new ObjectName(
    "jboss:readonly=true,service=invoker,target=Naming,type=http");
String port = (String)server.getAttribute(on, "InvokerURLSuffix");

回答1:

Check your boot up log, there will be a line:

21:03:10,415 INFO  [Http11AprProtocol] Initializing Coyote HTTP/1.1 on http-127.0.0.1-8180

The last four numbers are your current port. [8180 in my case]



回答2:

You can fetch JBoss configuration details through JMX, but for that you will need provider_url for communication with JBoss.

    //---

    Hashtable props = new Hashtable();
    props.put(InitialContext.PROVIDER_URL, "jnp://localhost:1099");
    props.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

    InitialContext ctx = new InitialContext(props);

    MBeanServerConnection serverConn = (MBeanServerConnection)ctx.lookup("jmx/rmi/RMIAdaptor");

    ObjectName namingObject= new ObjectName("jboss:service=Naming");  
    Object rmiPort = serverConn.getAttribute(namingObject, "RmiPort");
    Object bindAddress = serverConn.getAttribute(name1, "BindAddress");
    Object port = serverConn.getAttribute(name1, "Port");

    System.out.println("rmiPort : "+rmiPort + "bindAddress : " + bindAddress + "port : "+port);

    String[] domains = serverConn.getDomains();

    for(int i =0; i < domains.length; i++){
        System.out.println(domains[i]);
    }

   ObjectName obj = ObjectName.getInstance("jboss.system", "type", "Server");
   Boolean serverStatus = (Boolean) serverConn.getAttribute(obj, "Started");
   System.out.println("Server started : "+serverStatus);

    //---

You can use other attributes to fetch information.

Otherwise, you can parse the configuration file (jboss-service.xml) & extract the details from there.



回答3:

It's late for answer but you could read the server.xml in jbossweb.sar under deploy directory of your profile. In that file you has the port of Coyote and others configuration parameters. This file is really usefull and it is the same that you use in Tomcat.

Also you can use "lsof -i tcp:8080" to check if this port is binding to JBoss AS or "netstat -nlp". But if you don't know the port I think the best is read server.xml.

I hope the answer could help to anyone who read it.



回答4:

Executeps -ef to check the jboss process.

There check for the following parameter.

-Djboss.socket.binding.port-offset=1010

Add 8080 to the offset value, you will get the port that jboss is listening to. Example, for me jboss is listening to 9090 port. So (8080 + offset<1010> = 9090)



标签: jboss