Getting instance name of a WebSphere app Server

Michele Bortolato picture Michele Bortolato · May 16, 2012 · Viewed 30.1k times · Source

My Web service will run on a Jboss App Server or a Websphere app Server. For both of them I need to know the instance name, for Jboss I can use System.getProperty("jboss.server.name"), but what can I use for WebSphere? I can't use WebSphere-specific methods, I need to call System.properties

Thanks

Answer

IsidroGH picture IsidroGH · Oct 3, 2013

An alternative, at least for WebSphere, is to look it up in the JNDI tree. This is what I use:

InitialContext ic = new javax.naming.InitialContext();
String serverName = ic.lookup("servername").toString();

This way I don't have to configure anything as WebSphere binds that information for me.

Cell and node name can also be retrieved using "thisNode/cell/cellname" and "thisNode/nodename". Something useful in clusters.