Adam Bien's Weblog

Tuesday Dec 08, 2009

Is Java EE 6 War The New EAR? The Pragmatic Modularization And Packaging

It is not only possible to put EJBs and JSR-299 Beans together directly into a WAR - EJBs can be also packaged separately into a JAR. After copying the “ejb-jar” into the [WAR]/WEB-INF/lib folder, the included beans become automatically available to the web app. No additional configuration or tweaking is required. In the contrary to the the old EAR packaging, all the classes are loaded with the same classloader. There is no difference between packaging the beans in a standalone JAR, or putting the byte code directly into the WEB-INF/classes folder.

You could even sprinkle the beans in as many JARs as you like - the Dependency Injection between them will just work. Because all the JARs inside the WEB-INF/lib are loaded by exactly the same classloader - it just behaves like a single JAR.

It’s only deployment - but makes it very interesting for maven:

You can partition your project into one WAR-module, which has a compile-scoped dependency to several <packaging>jar</packaging> typed modules. Maven will create the (EJB)-JARs and copy them for you into the WEB-INF/lib location. The new Java EE 6 WAR-packaging is interesting for the majority of the “business” projects with “weak” requirements regarding the modularization. You can partition your software into dependent pieces, without paying the costs of true JAR-isolation.

The EAR packaging is still interesting for projects with higher modularization requirements - here the EJB-JARs will be loaded with an isolated classloader separately. In the majority of all cases it is just an overhead: it is unlikely, that someone will replace a single EJB-JAR without rebuilding and testing the whole EAR...


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Kommentare:

Nice to bring this feature to the forefront; a question we often hear in our EJB3 forums is about JEE5 injection of EJBs into servlets and why it's not correctly working.

Regarding the unified packaging itself, though; It's the Maven/Ant configurations for packaging that lead us to start the ShrinkWrap[1] project; too often I had to change or fight with my project structure to get artifacts in their expected form.

[1] http://jboss.org/shrinkwrap

Gesendet von Andrew Lee Rubinger am December 08, 2009 at 08:07 PM CET #

@Andrew,

looks very good. I especially like the fluent-API. In the process of setting-up a test :-)

Thanks for the pointer!,

adam

Gesendet von Adam Bien am December 08, 2009 at 11:06 PM CET #

Senden Sie einen Kommentar:
  • HTML Syntax: Ausgeschaltet
Interviews/About
My Recent Book
Java One 2009
CommunityOne East N.Y.C
JavaONE 2008 Interview
Search
...the last 150 posts
...the last 10 comments
greenfire.dev.java.net
Links
my.netbeans.org
Visitors
License