JBoss.org Community Documentation

14.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.INITIAL_CONTEXT_FACTORY,   
	"org.jnp.interfaces.NamingContextFactory");  
	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”).

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.