JNDI and Bean need help

S

shoa

Hello,

In my Client application, to get an entity bean (EntityBean) from from
server, I have this code in a client java file (a class):

public static void getEBean() throws CreateException, RemoteException,
NamingException
{
Properties pro = new Properties();
pro.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
pro.put("java.naming.factory.url.pkgs",
"org.jboss.naming:eek:rg.jnp.interfaces");
pro.put("java.naming.provider.url","localhost:3306");
InitialContext initialContext = new InitialContext(pro);

//I use a SessionFacade bean

EntityBeanSessionFacadeHome home =
(EntityBeanSessionFacadeHome)initialContext.lookup("EntityBeanSessionFacade"
);

//print name for a student - for testing

System.out.println(home.create().getStudentDetails(6).getStudentName());
}

This client application runs well. However, you can see that the code for
lookup is not good as it is hard code. Therefore, I created a file called
"jndi.properties" with the code:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:eek:rg.jnp.interfaces
java.naming.provider.url=localhost:3306

I put this file INTO the same level (e.g the same folder in hierarchy) with
the java file above then change the code above to:

public static void getEBean() throws CreateException, RemoteException,
NamingException
{
InitialContext initialContext = new InitialContext();
//I use a SessionFacade bean
EntityBeanSessionFacadeHome home =
(EntityBeanSessionFacadeHome)initialContext.lookup("EntityBeanSessionFacade"
);
//print name for a student - for testing

System.out.println(home.create().getStudentDetails(6).getStudentName());
}

However I get a Exception

javax.naming.NoInitialContextException: Need to specify class name in
environment or system property or as an applet parameter, or in an
application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:640)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at
javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at untitled3.ClientEnter.getEBean(ClientEnter.java:52)
at untitled3.ClientEnter.main(ClientEnter.java:85)


Could you please help
Many thanks
S.Hoa
 
H

HalcyonWild

You need to specify the properties file while creating the
InitialContext in the second case. Also, make sure if jndi.properties
is not a system file. I mean if a file with the same name is used by
the app server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top