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.
If you have multiple
jndi.propertiesfiles in the root of the classpath, thenInitialContextwill 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
InitialContexthas a constructor that takes aHashtableof properties, where you can specify them explicitly. That would be preferable to implicit loading viajndi.properties, in this case. You can always load your targetjndi.propertiesinto aPropertiesobject (which is a subclass ofHashtable), and pass that to the constructor.