Even I am getting the same exception:
My Directory structure is given in attachment
This is the code of clientBean.java which is accessing the EJB:
package example;
import java.rmi.RemoteException;
import java.util.Hashtable;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;
public class ClientBean {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
TestSessionBeanHome testSessionBean;
try {
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:5070");
InitialContext ctx = new InitialContext(ht);
//Look up the home or factory object on the WebLogic JNDI tree
Object objref = ctx.lookup("TestSessionBean");
if (objref == null)
{
System.out.println("problem in getting Home object");
}
testSessionBean= (TestSessionBeanHome)objref;
//testSessionBean = (TestSessionBeanHome)PortableRemoteObject.narrow(objref,TestSessionBeanHome.class);
System.out.println("Calling Session Bean");
TestSessionBean beanRemote;
beanRemote = testSessionBean.create();
beanRemote.SayHello();
beanRemote.remove();
//close the InitialContext
ctx.close( );
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
This is the Remote Object TestSessionBean.java
package example;
import javax.ejb.*;
public interface TestSessionBean extends javax.ejb.EJBObject{
public String SayHello() throws java.rmi.RemoteException;
}
This is the Home Interface TestSessionBeanHome.java
package example;
import javax.ejb.*;
public interface TestSessionBeanHome extends javax.ejb.EJBHome {
public example.TestSessionBean create()throws javax.ejb.CreateException,java.rmi.RemoteException;
}
This is the SessionBean MyTestSessionBean.java
package example;
import javax.ejb.*;
import java.rmi.RemoteException;
public class MyTestSessionBean implements SessionBean{
public void ejbCreate()throws CreateException{
}
public void setSessionContext(SessionContext aContext)throws EJBException{
}
public void ejbActivate()throws EJBException{
}
public void ejbPassivate()throws EJBException{
}
public void ejbRemove()throws EJBException{
}
public String SayHello(){
String msg="Hello World";
System.out.println(msg);
return msg;
}
}
EJB-JAR:
\<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<description>EJB Examples</description>
<display-name>EJB Examples</display-name>
<enterprise-beans>
<!-- Session Beans -->
<session>
<description>EJB Test Session Bean</description>
<display-name>EJB Test Session Bean</display-name>
<ejb-name>TestSessionBean</ejb-name>
<home>example.TestSessionBeanHome</home>
<remote>example.TestSessionBean</remote>
<ejb-class>example.MyTestSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>TestSessionBean</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>Test Bean</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
</ejb-jar>
WEBLOGIC_EJB_JAR:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC
"-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN"
"http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd" >
<weblogic-ejb-jar>
<description>Session Bean Example</description>
<weblogic-enterprise-bean>
<ejb-name>TestSessionBean</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<reference-descriptor>
</reference-descriptor>
<jndi-name>TestSessionBean</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
and finally the error while running the client code in ecclipse after deploying the jar on weblogic 8.1 server:
javax.naming.NameNotFoundException: Unable to resolve 'TestSessionBean' Resolved [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'TestSessionBean' Resolved ]; remaining name 'TestSessionBean'
at weblogic.rjvm.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:108)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:290)
at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:248)
at weblogic.jndi.internal.ServerNamingNode_816_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:375)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:363)
at javax.naming.InitialContext.lookup(Unknown Source)
at example.ClientBean.main(ClientBean.java:24)
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'TestSessionBean' Resolved
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:924)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:230)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:154)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:188)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:491)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:120)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:434)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:429)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
Please help