[jboss-user] [JNDI/Naming/Network] - Getting Exception in client code while JNDI Lookup(EJB 2.0 a

sharma.nalin83 do-not-reply at jboss.com
Sat Nov 3 04:53:46 EDT 2007


Hi All,

I have created a EJB proect as follows:

(1) Stateless EJB class
(2) Home Interface
(3) Remote Interface

(4) ejb-jar.xml as below:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
	<display-name>MyEJB</display-name>
<!--  	<ejb-client-jar>EJBProjectClient.jar</ejb-client-jar> -->
<enterprise-beans>
 
   <ejb-name>MyBean</ejb-name>
   src.MyBeanHome
   src.MyRemoteBean
   <ejb-class>src.MyBean</ejb-class>
   <session-type>Stateless</session-type>
   <transaction-type>Container</transaction-type>
 
</enterprise-beans>
</ejb-jar>


(5) jboss.xml as below:

<?xml version="1.0" encoding="UTF-8"?>

  <enterprise-beans>
    
       <ejb-name>MyBean</ejb-name>
       <local-jndi-name>ejb/myEJBMapping</local-jndi-name>
    
  </enterprise-beans>


(6) and below is my client code:

package MyClient;


import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

import java.rmi.*;
import java.util.Hashtable;
import java.util.Properties;

import javax.ejb.*;
import src.*;
public class MyClient{
     public static void main(String[] args){
         try{
//        	  Get an initial context
        	 InitialContext jndiContext = new InitialContext(properties);
        	 System.out.println("Got context");

//        	  Get a reference to the Bean
        	 Object ref = jndiContext.lookup("ejb/myEJBMapping");
        	 System.out.println("Got reference");

//        	  Get a reference from this to the Bean's Home interface
        	 MyBeanHome home = (MyBeanHome)
        	 PortableRemoteObject.narrow (ref, MyBeanHome.class);

//        	  Create an Adder object from the Home interface
        	 MyRemoteBean sp = home.create();
         }catch(RemoteException rex){
             rex.getLocalizedMessage();
         }catch(Exception e){
        	 e.printStackTrace();         }
     }

 }


After running the client code getting below 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:645)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
	at javax.naming.InitialContext.lookup(InitialContext.java:351)
	at MyClient.MyClient.main(MyClient.java:78)


Can anyone please suggest over this?

Thanks in advance.

~Regards
Nalin Sharma
CTS || Chennai

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101513#4101513

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101513



More information about the jboss-user mailing list