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.namingrg.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.namingrg.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
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.namingrg.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.namingrg.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