Thursday, July 1, 2010

Collapsed EARs a.k.a EJBs in WARs

Java EE 6 supports using of EJBs in web applications. If you do not know how EJBs are simplified starting with Java EE 5, time to look at them again. Lots of folks still think that EJBs are heavy and must be run on the heavy containers. This is not TRUE any more.

EJBs are great because it supports Transactions, Security, Messaging, Scheduling, Asynchronous, and lots of cool enterprise features. But the most important is that "it is A Java EE STANDARD".

For example, our Defne Service Framework is a thin layer on top of this great technology for providing transaction support.

Using EJBs in WARs

This is really the cool feature of Java EE 6. Even before releasing the Java EE 6, OpenEJB has already supported this cool feature. What does it mean? It means that you can bundle your EJBs within your web application archives. How?


public class Calculator implement ICalculator{
      public int add(int x,int y)

Use in JSF Bean;
public class CalculatorBean
    private @EJB ICalculator calculator;

Use in OpenWebBeans Managed Bean
public classd CalculatorBean
    private @Inject ICalculator calculator;

Use in OpenWebBeans Managed Bean via @EJB
public classd CalculatorBean
    private @EJB ICalculator calculator;


That is it! No more configuration files, xmls etc. Bundle all of the necessary classes as a WAR archive and deploy it to the container that supports collapsed ears.

Want to use transaction, security, scheduling, no problem! Just annotate your EJB methods with the necessary annotation marker. Even if you do not want to annotate, there are some default configurations. For example, all business methods within EJBs are automatically Transaction Required.

SIwpas and EJBs

SIwpas Beta-2 will support the EJBs. SIwpas will contain the OpenEJB to support EJBs in WARs.  Beta-2 will be published at the end of this week.

Java EE 6 has a cool features and main motivation is the SIMPLICITY!

Stay tune!


J2Flower said...

very interesting project!

i tried all your samples (i suggest to mavenize all sample projects -for begginers is very useful:

I added to your siwpas-sample-collapse project also openjpa:
now it not work, but i will try again in the coming days.

best regards


Gurkan Erdogdu said...

Thanks for your comments Fiorenzo.