tags:

views:

283

answers:

1

I have a jboss web service that is getting the wrong initial context. I want it to use the java.naming.factory.initial from the jndi.properties in the services root directory and not the one in jboss jndi.properties which is the NamingContextFactory. In the ant build file I put the jndi.properties in the classpath and made sure it copies over to the archive, but the service still gets the NamingContextFactory instead. How can I tell which jndi.properties gets used so that the factory gets set correctly?

The unfortunate situation is that I have a third party jar I must use that expects its initial context factory to be the one specified in its packaged jndi.properties file, but when I run this in jboss it gets NamingContextFactory. I can't change the jboss jndi.properties file without everything breaking.

+1  A: 

If you have multiple jndi.properties files in the root of the classpath, then InitialContext will make some attempt to merge the two, but which one wins is more or less a matter of chance.

If you want to make sure, then InitialContext has a constructor that takes a Hashtable of properties, where you can specify them explicitly. That would be preferable to implicit loading via jndi.properties, in this case. You can always load your target jndi.properties into a Properties object (which is a subclass of Hashtable), and pass that to the constructor.

skaffman
Edited my post to include that I don't control the initial context request a third party library does... :(
insipid