First of all, your xml file indicates that you are using EJB3 (this is actually the only version worth considering), but your bean is an EJB2 bean.
If your server really runs EJB3, delete the XML file and remove the unnecessary home and component EJB implementations. Add the @Stateless and remote interface. Make sure it looks something like this:
@Remote public interface SinaRemote { String getHello(); } @Stateless public class SinaBean implements SinaRemote { public String getHello() { return "hello"; } }
Then fix your JNDI properties. The following is not true:
p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.namingrg.jnp.interfaces");
it should be:
p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
(the options used here are almost endless, and in principle they always work, but just to use the correct option)
In addition, and most likely the main culprit, you are using ejb-name as - if this is the global JNDI name, but it is not. ejb-name is a somewhat confusing logical name that is used as an additional kind of qualifier when referring to a specific bean when injecting or creating ejb-ref.
In your case, you install it in the same way as the unqualified name bean, which is already the default value. Since there is SinaBean , I assume that you are not deploying through the EAR, but are deploying an autonomous EJB, right?
If you use JBoss AS 6 (EJB3.1), you can use the global JNDI portable names, otherwise the old JBDI JBoss name can be used: [ear name]/[simple bean name]/remote . Note that [simple bean name] is not an ejb name, but again in your case they turned out to be the same. Since [ear name]/ is deleted when you deploy only the EJB, this explains the exception you get: SinaBean is a directory (context in JNDI terms) that can contain the actual local , remote and no-interface entries. What you are doing is trying to pass this intermediate node directory to the proxy server on your bean, which of course does not work.
In the end, remove the use of PortableRemoteObject , this is no longer required . Client code will look like this:
Properties properties = new Properties(); properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); properties.setProperty(Context.PROVIDER_URL, "localhost:1099"); context = new InitialContext(properties); SinaRemote sina = (SinaRemote) context.lookup("SinaBean/remote");