TechCrunch TechCrunch - 3 months ago 21
Java Question

NameNotFoundException when using JBoss 7.1.1

I'm creating an EJB application and I'm using below to get the context

Context context = new InitialContext();
StudentEJBRemote remoteHandle;
remoteHandle = (StudentEJBRemote) context.lookup("java:global/stadikon_hw2/swe645a1/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote");


I get below error when I try to do this.

javax.naming.NameNotFoundException: stadikon_hw2/swe645a1/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote -- service jboss.naming.context.java.global.stadikon_hw2.swe645a1."StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote"
org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
org.jboss.as.naming.InitialContext.lookup(InitialContext.java:123)
org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
javax.naming.InitialContext.lookup(InitialContext.java:411)
masonsurvey.SurveyAction.execute(SurveyAction.java:37)


I've deployed the client application and EJB in a .ear file in JBoss. The client application .war file contains the jar of the remote interface class.

From the logs, I can see that binding happened.

17:01:18,821 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-7) JNDI bindings for session bean named StudentEJB in deployment unit subdeployment "stadikon_session_hw2.jar" of deployment "stadikon_hw2.ear" are as follows:

java:global/stadikon_hw2/stadikon_session_hw2/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:app/stadikon_session_hw2/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:module/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:jboss/exported/stadikon_hw2/stadikon_session_hw2/StudentEJB!masonsurveyejb.businesslogic.StudentEJBRemote
java:global/stadikon_hw2/stadikon_session_hw2/StudentEJB
java:app/stadikon_session_hw2/StudentEJB
java:module/StudentEJB

Answer

I solved this by adding properties in the source code.

// Configure JNDI properties.
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
        "org.jnp.interfaces.NamingContextFactory");
jndiProps.put(Context.PROVIDER_URL, "remote://localhost:1099");
jndiProps.put(Context.URL_PKG_PREFIXES,
        "org.jboss.naming.org.jnp.interfaces");

Context context = new InitialContext();