如何得到EJB组件

如果为jboss则注意要引用jbossall-client.jar包 javax.naming.InitialContext initialContext 要引用
environment.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.jnp.interfaces.NamingContextFactory");
        environment.put(Context.PROVIDER_URL, "127.0.0.1:1099");
        javax.naming.InitialContext initialContext = new javax.naming.InitialContext(
                environment);
        try
        {
            objRef = initialContext
                    .lookup(ServiceHome.JNDI_NAME);
            // only narrow if necessary
            if (java.rmi.Remote.class
                    .isAssignableFrom(ServiceHome.class))
                objRef = javax.rmi.PortableRemoteObject.narrow(objRef,
                        serviceHome.class);
            ServiceHome serviceHome = (ServiceHome) objRef;
            service = serviceHome.create();
        }
        finally
        {
            initialContext.close();
        }

你可能感兴趣的:(java,jboss,ejb)