Question

I am learning basics of EJB 3.0. I have managed to get a sample code up and running. Now I am doing a line by line analysis to have in-depth knowledge. But I am stuck at few lines where there is a lookup to find the required bean.

Can anyone please explain me in simple language the meaning and the need of the following lines?

Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");
properties.setProperty(Context.PROVIDER_URL, "localhost:1099");

IniialContext context = null;
SamleEjbRemote cl = null;
try {
    context = new InitialContext(properties);
    cl = (SampleEjbRemote) context.lookup("SampleEjbBean/remote");
} catch (NamingException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}


What is the exact meaning of each of the 'key' and 'value' that is used in properties?

Rest of it is to put the 'properties' in the initial context instance. I have had a very vague idea of the above, but I want to clarify it very clearly. I would be glad if anyone could point me to any links or insights about the above lines.

Thanks in advance.

Was it helpful?

Solution

Both properties configures JBoss JNDI HTTP InitialContext Factory Implementation

Official document here : http://docs.jboss.org/jbossas/jboss4guide/r1/html/ch3.chapter.html

See chapter 3.2.1.2. The HTTP InitialContext Factory Implementation

java.naming.factory.initial: The name of the environment property for specifying the initial context factory, which must be org.jboss.naming.HttpNamingContextFactory.

java.naming.factory.url.pkgs: For all JBoss JNDI provider this must be org.jboss.naming:org.jnp.interfaces. This property is essential for locating the jnp: and java: URL context factories of the JBoss JNDI provider.

UPDATE:

I would recommend to use jndi.properties file in your class path

### JBossNS properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://localhost:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top