Inside Scoop on J2EE : Tips and tricks on J2EE and Oracle Application Server by Debu Panda
Updated: 2/3/2005; 8:40:06 PM.

 

Subscribe to "Inside Scoop on J2EE" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Tuesday, January 25, 2005

 

After I published my last blog Using EJB 3.0: Lean and Thin EJB, I got few emails from developers asking me to send them the code for HelloWorld EJB that use annotations. Couple of them asked whether ejb-jar.xml would no longer be used? Yes, EJB 3.0 is trying to remove the requirement of packaging ejb-jar.xml for those who hate XML by using defaults and exploiting use of metadata annotation. However you will be able to override annotation by packaging XML deployment descriptors.

 

Here is the content of my XML deployment descriptor that I used in earlier HelloWorld EJB.

 

<ejb-jar>

  <enterprise-beans>

    <session>

      <description>Session Bean ( Stateless )</description>

      <display-name>HelloWorld</display-name>

      <ejb-name>HelloWorld</ejb-name>

      <remote>oracle.ejb30.HelloWorld</remote>

      <ejb-class>oracle.ejb30.HelloWorldBean</ejb-class>

      <session-type>Stateless</session-type>

    </session>

  </enterprise-beans>

  </ejb-jar>

 

The only change in this deployment descriptor with respect to EJB 2.1 is that I do not have <home> defined for the EJB.

 

I modified my HelloWorld EJB as follows to get rid of the ejb-jar.xml

 

package oracle.ejb30;

import javax.ejb.Stateless;

 

@Stateless

public class HelloWorldBean implements HelloWorld

{

 

  public String sayHello(String nom)

  {

    final String result = "Hello " + nom + " from your EJB 3.0 with annotation";

    System.out.println(result);

    return result;

  }

 

}

 

I compiled and packaged the bean class and remote interface and deployed to my container and the client application was ready to go. Isn't this neat?

 

Annotations will really simplify developers' life but you have to be careful because overuse of annotations can make your application less portable.


6:55:27 AM    comment []

© Copyright 2005 Debu Panda.

PS: These are my own thoughts and not of my employer ..



Click here to visit the Radio UserLand website.
 


January 2005
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Dec   Feb