IIOP standalone EJB3 client lookup to Glassfish 3.1.2

Setup to run a standalone EJB client and lookup to a Glassfish running EJB 3.1 stateless ejb.

  • Install Glassfish plugin in Eclipse.
  • Create a Enterprise Aplication Project using Glassfish server as the target runtime.
  • Create a HelloWorld example:
@Remote
public interface HelloWorld {}

@Stateless
public class HelloWorldEjb implements HelloWorld {}
  • Create a Application Client Project using Glassfish server as the target runtime.
  • Add gf-client.jar to the project classpath. gf-client.jar is included on the glassfish plugin folder inside eclipse, or in the glassfish standalone installation.
  • Create the plain java code as the following:
InitialContext ctx;
HelloWorld ejbRef = null;
try {
   ctx = new InitialContext();

   ejbRef = (HelloWorld) ctx.lookup("eu.pedrocardoso.HelloWorld");

   System.out.println(ejbRef.getMessage("Hello"));

} catch (NamingException e) {
   e.printStackTrace();
}

 

  • Optionally we can give properties to the initial context:
Properties p = new Properties();
p.put("org.omg.CORBA.ORBInitialHost","localhost");
p.put("org.omg.CORBA.ORBInitialPort","3700");

Default Glassfish iiop port is 3700

Tags: ,

Leave a Reply