Getting NameNotFoundException while running client program of EJB
<p>I am new to EJB.</p>

<p>I am trying to learn to develop a stateless bean. I created the jar file and deployed it on Weblogic server and then i executed the client code. I have already set the classpath for <em>api.jar</em> and <em>weblogic.jar</em>. But on running client code i am getting following error:</p>

<pre><code>C:\Users\Asad\Desktop\EJB&gt;java EjbClient1
Exception in thread "main" javax.naming.NameNotFoundException: Unable to resolve 'myAdder#Adder'. Resolved '' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'myAdder#Adder'. Resolved '']; remaining name 'myAdder#Adder'
        at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1224)
        at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:273)
        at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:217)
        at weblogic.jndi.internal.BasicNamingNode.lookupIgnorePartition(BasicNamingNode.java:1503)
        at weblogic.jndi.internal.PartitionHandler.lookupSharable(PartitionHandler.java:88)
        at weblogic.jndi.internal.ServerNamingNode.lookup(ServerNamingNode.java:584)
        at weblogic.jndi.internal.RootNamingNode.lookup(RootNamingNode.java:81)
        at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
        at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:645)
        at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:248)
        at weblogic.rmi.internal.BasicServerRef$2.run(BasicServerRef.java:534)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:368)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:163)
        at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:531)
        at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:137)
        at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
        at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
        at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
        at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
        at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:617)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:397)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'myAdder#Adder'. Resolved ''
        at weblogic.utils.StackTraceDisabled.unknownMethod()
</code></pre>

<p>Following is the code.</p>

<p>Client EjbClient1.java:</p>

<pre><code>import javax.naming.*;
import java.util.*;
import javax.naming.Context;  
import javax.naming.InitialContext;  

public class EjbClient1 {
    public static void main(String s[])throws Exception {
        Properties parm=new Properties();
        parm.setProperty("java.naming.factory.initial","weblogic.jndi.WLInitialContextFactory");
        parm.setProperty("java.naming.provider.url","t3://localhost:7001");
        parm.setProperty("java.naming.security.principal","weblogic");
        parm.setProperty("java.naming.security.credentials","asad9711");
        // parm.setProperty("java.naming.security.credentials","weblogic12");

        InitialContext ctx=new InitialContext(parm);
        Adder stub=(Adder)ctx.lookup("myAdder#Adder");

        int c=stub.add(10,20);
        System.out.println(c);

    }
}
</code></pre>

<p>Bean class AdderBean.java:</p>

<pre><code>import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Stateless;

@Stateless(mappedName="myAdder")
class AdderBean implements Adder {
    @PostConstruct  
    public void init()
    {
        System.out.println("post create");

    }
    @PreDestroy
    public void destroy()
    {
        System.out.println("destroy");
    }
    public int add(int x,int y)
    {
        return x+y;
    }
}
</code></pre>

<p>Remote Interface Adder.java:</p>

<pre><code>import javax.ejb.Remote;

@Remote
public interface Adder
{
     int add(int x,int y);
}
</code></pre>