Monday December 19, 2005 EJB 3.0 client in J2SE project Today, I would like to show how you can create client for EJB 3.0 in J2SE project. First, we will need to create a bean with remote interface. Since, we are using EJB 3.0 this is very simple. Create business interface with Remote annotation and then create bean's implementation class of your bean and specify JNDI name of this bean:
@Stateless(name="ejb/ProcessHello")
public class ProcessHelloBean implements org.netbeans.ProcessHello {
public void String getHello(){
....
Now, we have two ways how to create client. First one is using Application Client Container (ACC) and second one is without that. What is advantage of the ACC? ACC can be seen as lightweight container that is responsible for security, naming, communication with application server and especially for injection. However, the worse of this approach is that you need run your application with appclient launcher. The client that
uses ACC can be written like:
@EJB(name="ejb/ProcessHello")
private org.netbeans.ProcessHello hello;
hello.getHello();
Then you need to run your client's jar with launcher appclient -client
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("org.netbeans.ProcessHello");
ProcessHello hello = (TestTableRemote)PortableRemoteObject.narrow(obj, ProcessHello.class);
hello.getHello();
In this sample I used default JNDI name that is fully qualified classname of the remote business interface (3.0) or remote home interface (2.x). If you want to change the JNDI name use mappedName attribute for @Stateless.
Posted by pblaha
( Dec 19 2005, 06:11:29 PM CET )
Permalink
Comments [5]
One very important feature of GlassFish is the ability to distribute your Java EE app client via Java Web Start.
This allows developers to create an application client (using Java EE 5 features like injection) and allows an enterprise to do almost painless application provisioning.
This document has some more information that might be useful.
Posted by 192.18.42.10 on December 19, 2005 at 07:50 PM CET #
Is such support also in other Application Server?
Posted by Christopher Atlan on December 19, 2005 at 09:17 PM CET #
Posted by 192.18.1.5 on December 20, 2005 at 08:54 AM CET #
Posted by 193.108.250.112 on December 22, 2005 at 10:25 AM CET #
@EJB(name="ejb/ProcessHello") private static org.netbeans.ProcessHello hello;Posted by Sahoo on December 22, 2005 at 03:27 PM CET #