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...
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 project; too often I had to change or fight with my project structure to get artifacts in their expected form.
Posted by Andrew Lee Rubinger on December 08, 2009 at 09:07 PM CET #
looks very good. I especially like the fluent-API. In the process of setting-up a test :-)
Thanks for the pointer!,
Posted by Adam Bien on December 09, 2009 at 12:06 AM CET #
Nice! Its very painfull work with EAR mainly if your modules have to be deployed every time in development. Using IDE's with hot deployment don't work with ear projects.
Posted by Giovanni Candido on May 21, 2011 at 07:41 PM CEST #
look at: http://java.net/projects/x-ray Also a Java EE 6-WAR example,
Posted by Adam Bien on May 21, 2011 at 09:26 PM CEST #
Yeah, I love this feature!
I guess that you just need to remember about possible name clashes, as all the EJB components are sharing the same environment and namespace in opposed to the EJB-JAR.
Posted by PedroKowalski on August 08, 2011 at 06:21 PM CEST #
But when you have 'n' wars inside a EAR, this migration still not possible.
Posted by Jairo Ricarte on August 24, 2015 at 05:20 PM CEST #