|
Page Edited :
OPENEJB :
Getting Started
Getting Started has been edited by Karan Singh Malhi (Aug 30, 2007). Content:The following instructions are written using Eclipse 3.2. We will refer to the install location of OpenEJB as OPENEJB_HOMEHere are some basic steps you need to perform to get started with OpenEJB
1. Download and Install OpenEJBFollow these instructions 2. Setup your development environmentEclipse
3. Start the ServerOpen the command prompt and run the following command: d:\openejb-3.0.0-SNAPSHOT\bin\openejb start You will get the following message on the console: 4. Write an EJBIn the EJB project create a new interface named Greeting package com.myejbs; import javax.ejb.Remote; @Remote public interface Greeting { public String greet(); } Now create a new class named GreetingBean which implements the above interface (shown below) package com.myejbs; import javax.ejb.Stateless; @Stateless public class GreetingBean implements Greeting { public String greet() { return "My First Remote Stateless Session Bean"; } } 5. Deploy the EJB#Export the EJBProject as a jar file. Name it greeting.jar and put it in the OPENEJB_HOME/apps directory. This should give you the following output: D:\openejb-3.0.0-SNAPSHOT>bin\openejb deploy apps\greeting.jar
Application deployed successfully at \{0\}
App(id=D:\openejb-3.0.0-SNAPSHOT\apps\greeting.jar)
EjbJar(id=greeting.jar, path=D:\openejb-3.0.0-SNAPSHOT\apps\greeting.jar)
Ejb(ejb-name=GreetingBean, id=GreetingBean)
Jndi(name=GreetingBeanBusinessRemote)
Notice the Jndi(name=GreetingBeanBusinessRemote) information. Keep this handy as this is the JNDI name of the bean which the client will use for lookup 6. Write the ClientIn the EJBClient project, create a class named Client (shown below) package com.myclient; import java.util.Properties; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; import com.myejbs.Greeting; public class Client { public static void main(String[] args) { try { Properties p = new Properties();p.put("java.naming.factory.initial", "org.openejb.client.RemoteInitialContextFactory"); p.put("java.naming.provider.url", "127.0.0.1:4201"); InitialContext ctx = new InitialContext( p ); Object object = ctx.lookup("GreetingBeanBusinessRemote"); Greeting greeter = (Greeting) PortableRemoteObject.narrow(object, Greeting.class); String message = greeter.greet(); System.out.println(message); } catch (NamingException e) { e.printStackTrace(); } } } 7. Run the ClientOpen Client.java in eclipse and run it as a java application. You should see the following message in the console view: My First Remote Stateless Session Bean 8. Stop the serverYou can press Ctrl+c on the command prompt to stop the server |
Unsubscribe or edit your notifications preferences
