Here is my client code that call a simple Statefull Session bean: | public static void go() throws Exception{ | | Context ic = new InitialContext(); | Object o = ic.lookup("Hello"); | HelloHome home = (HelloHome) PortableRemoteObject.narrow(o,HelloHome.class); | Hello helloer = home.create("Test"); | System.out.println("From EJB: "+helloer.hello()); | helloer.remove(); | } | public static void main(String[] args) | { | try{ | go(); | } | catch(Exception ex){ | ex.printStackTrace(); | } | | } | ----------------------------------------------------------------------- Here is my jboss.xml :
| <jboss> | | <enterprise-beans> | | <!-- | To add beans that you have deployment descriptor info for, add | a file to your XDoclet merge directory called jboss-beans.xml that contains | the <session></session>, <entity></entity> and <message-driven></message-driven> | markup for those beans. | --> | | <session> | <ejb-name>Hello</ejb-name> | <jndi-name>ejb/Hello</jndi-name> | | </session> | | </enterprise-beans> | | <resource-managers> | </resource-managers> | | </jboss> | ----------------------------------------------------------------- Here is the Bean (I use JBOSS IDE to design it): | public class HelloBean implements SessionBean { | | /** | * | */ | private SessionContext context; | private String userName; | public HelloBean() { | super(); | // TODO Auto-generated constructor stub | } | | /* (non-Javadoc) | * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext) | */ | public void setSessionContext(SessionContext ctx) | throws EJBException, | RemoteException { | context = ctx; | System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); | System.setProperty("java.naming.provider.url","localhost:1099"); | } | | /* (non-Javadoc) | * @see javax.ejb.SessionBean#ejbRemove() | */ | public void ejbRemove() throws EJBException, RemoteException { | // TODO Auto-generated method stub | } | | /* (non-Javadoc) | * @see javax.ejb.SessionBean#ejbActivate() | */ | public void ejbActivate() throws EJBException, RemoteException { | // TODO Auto-generated method stub | } | | /* (non-Javadoc) | * @see javax.ejb.SessionBean#ejbPassivate() | */ | public void ejbPassivate() throws EJBException, RemoteException { | // TODO Auto-generated method stub | } | | /** | * Default create method | * | * @throws CreateException | * @ejb.create-method | */ | public void ejbCreate() throws CreateException { | // TODO Auto-generated method stub | } | public void ejbCreate(String name) throws CreateException { | userName = name; | } | /** | * Business method | * @ejb.interface-method view-type = "remote" | */ | public String hello() { | // TODO Auto-generated method stub | return "Hello from Stateless Session Bean"+ userName; | } | } | ------------------------------------------------------ I get this error: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.lookup(Unknown Source) at tutorial.client.ClientTest.go(ClientTest.java:30) at tutorial.client.ClientTest.main(ClientTest.java:39) ------------------------------------------------------ Thank you for your help, if you think you need any further info please ask me to send them. Because I use Jboss IDE for EJB3 I don't think it is necessary to post my Home and Component interface but if it is necessary please inform me. THANX View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3894158#3894158 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3894158 ------------------------------------------------------- SF.Net email is Sponsored by the Better Software Conference & EXPO September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user