Instructions on how to deploy
a stateless session bean
Remember to leave no spaces
in the paths.
We will now create a new
EJB.
Deploy the ejb:
Some problems I encountered and their solutions:
Create the client:
package
ssd.mse.client; import java.rmi.RemoteException; import java.util.Hashtable; import javax.ejb.CreateException; import javax.naming.InitialContext; import javax.naming.NamingException; import ssd.mse.YouWin; import ssd.mse.YouWinHome; public class YouWinClient { /** * @param args */ private YouWinHome getHome() throws NamingException { return (YouWinHome) getContext().lookup(YouWinHome.JNDI_NAME); } private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT props.put(InitialContext.PROVIDER_URL, "jnp://localhost:1099");
props.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp
//java.naming.factory.initial=org.jnp.interfaces.NamingContex
//java.naming.provider.url=jnp
//java.naming.factory.url.pkgs=org.jboss.naming:org.jnp InitialContext initialContext = new InitialContext(props); // InitialContext initialContext = new InitialContext(); return initialContext; } public void testBean() { try { YouWin myBean = getHome().create();
System.out.println("Result: " + myBean.youWin("Lucia")); } catch (RemoteException e) { e.printStackTrace(); } catch (CreateException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } }
public static void main(String[] args) { YouWinClient test = new YouWinClient(); test.testBean(); } } |