i am trying out EJB 3 example for remote method access. A simple example where in i am writing code and putting it in a jar. I have deployed the jar inside jboss server in C:\jboss-4.2.3.GA\server\default\deploy and the jar name is 01addproject.jar (exported from eclipse as EJB JAR File)
I am using another project to write the client code, to look up for the service and use the remote method in a simple way.
I feel the class is not getting registered in the RMI registry, which is giving NameNotFoundException when i run the client code as a PSVM Program.
This is the Error:
javax.naming.NameNotFoundException: AddRemoteImpl not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
(reduced as lack of space)
Package structure:
Code inside AddRemote.java
package com.cluster.remote;
import javax.ejb.Remote;
@Remote
public interface AddRemote {
void m1();
int add(int x, int y);
}
Code inside AddRemoteImpl.java
package com.cluster.remote;
import javax.ejb.Stateless;
@Stateless
public class AdddRemoteImpl implements AddRemote {
@Override
public void m1() {
System.out.println("inside m1");
}
@Override
public int add(int x, int y) {
return x + y;
}
}
Client Code (psvm program) inside Client.java
package clientcode;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.cluster.remote.AddRemote;
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
try {
AddRemote remote = (AddRemote) getInitialContext().lookup("AddRemoteImpl/remote");
System.out.println("The alue form the session bean is " + remote.add(3, 5));
System.out.println("Added Successfully");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Context getInitialContext() throws NamingException{
Hashtable hashtable = new Hashtable();
hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
hashtable.put(Context.PROVIDER_URL, "localhost:1099");
Context context = new InitialContext(hashtable);
return context;
}
}