JBoss.org Community Documentation

17.2.1. For clients running inside the application server

If you want to access HA-JNDI from inside the application server, you must explicitly get an InitialContext by passing in JNDI properties. The following code shows how to create a naming Context bound to HA-JNDI:

Properties p = new Properties();  
p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");  
p.put(Context.PROVIDER_URL, "localhost:1100"); // HA-JNDI port.  
return new InitialContext(p);

The Context.PROVIDER_URL property points to the HA-JNDI service configured in the HANamingService MBean (see the section called “JBoss configuration”).

However, this does not work in all cases, especially when running a multihomed cluster (several JBoss instances on one machine bound to different IPs). A safer method is not to specify the Context.PROVIDER_URL (which does not work in all scenarios) but the partition name property:

Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
p.put("jnp.partitionName", "DefaultPartition"); // partition name.
return new InitialContext(p);

Do not attempt to simplify things by placing a jndi.properties file in your deployment or by editing the AS's conf/jndi.properties file. Doing either will almost certainly break things for your application and quite possibly across the application server. If you want to externalize your client configuration, one approach is to deploy a properties file not named jndi.properties, and then programatically create a Properties object that loads that file's contents.


Previously, HANamingServiceMBean.bindAddress served two functions: From trunk/cluster/src/etc/hajndi-service.xml:

<!-- Bind address of bootstrap and HA-JNDI RMI endpoints -->
		<attribute name="BindAddress">${jboss.bind.address}</attribute>

The bootstrap and HA-JNDI RMI endpoints are now defined separately:

		<!-- Bind address of bootstrap endpoint -->
		<attribute name="BindAddress">${jboss.bind.address}</attribute>
		<!-- Bind address of the HA-JNDI RMI endpoint -->
		<attribute name="RmiBindAddress">${jboss.bind.address}</attribute>

They each default to the same value. Users may want to override the RMI bind address if deployed on a multi-homed machine, and want to use an specific network interface for HA-JNDI RMI calls. This ability already exists in the standard NamingService.