Create a jndi.properties file, place it in the classpath (usually in the base directory of the jar file), with these contents:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory java.naming.provider.url=localhost:1099 java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Of course, replace locahost with your host name if you are attempting remote access.
You can also provide those same properties within the application by creating a hash map and passing it to the InitialContext constructor.
From within the container, your InitialContext will be configured properly when using the default constructor. From a remote client (another JVM, like your JUnit Test), this isn't the case, and you'll have to get your context:
Hashtable<String, String> props= new Hashtable<String, String>(); props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); props.put(Context.PROVIDER_URL,"jnp://localhost:1099" ); props.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces" ); Context ctx = new InitialContext( props );
..replacing the host and port in Context.PROVIDER_URL with something appropriate.
Dependency injection...you'll have to do a lookup for that bean using the Context above - you'll only be able to inject container-managed resources into other container-managed resources.
Also, for a remote client junit test, I didnt see a jboss client jar in the lastest 4.04ga release. I found I had to add a bunch of jboss jars to the client runtime classpath. I cant recall what all i added but if it still a problem, I can find out and post another response.