EJB 2 and J2EE Packaging
Pages: 1, 2
So what is the right solution to this dilemma? One of the possible solutions is to eliminate the need for multiple JARs in your J2EE application by converging all of your EJBs and their utility classes into a single, unified package. The EJB 2.0 public final draft 2 (PFD2) specification is driving some projects to do this. This new version of the specification mandates that entity EJBs participating in a relationship do so using local interfaces and requires both of the EJBs in the relationship to be packaged into the same JAR file. PFD1 allowed EJBs in different JAR files to participate in relationships, further promoting greater modularity of the system, but ultimately limited the persistence optimizations that containers could do for CMP entity beans in a relationship. Now that PFD2 eliminates this capability, many vendors are providing tools that perform EJB JAR convergence. These tools will take as input two valid EJB JAR files and merge their contents and deployment descriptors into a single, unified package. You could potentially use one of these convergence tools to re-package your existing JAR applications.
Keep in mind that even if you converge all of your EJBs into a single JAR application, you will have eliminated copies of your utility library among the EJBs, but a copy will still exist in your
WEB-INF\lib library. Additionally, the need for modularity of EJB applications still exists, since many companies desire to re-deploy EJBs on an individual basis. Since every EJB in a JAR will be re-deployed when that JAR file is re-deployed, an unnecessary amount of deployment processing could occur if your only desire is to re-deploy a single EJB.
A Better Solution
With the release of JDK 1.3, Sun Microsystems redefined the "extension mechanism," which is the functionality necessary to support optional packages. The extension mechanism is designed to support two things:
- JAR files can declare their dependency upon other JAR files allowing an application to consist of multiple modules.
- Classloaders are modified to search optional packages and application paths for classes.
Additionally, the J2EE 1.3 specification's section 8.1.2 mandates that compliant application servers must support the extension mechanism as defined for JAR files. This requires that any deployment tool that references a JAR file be capable of loading any optional libraries defined through the extension mechanism. This also implies that if an application server or deployment tool supports runtime undeployment and re-deployment of EJB applications that use libraries via the extension mechanism, then that tool or application server must also support undeployment and re-deployment of any dependent libraries!
Support for the extension mechanism does not exist for EAR, WAR, or RAR
applications as defined in the J2EE specification, since these applications are not directly loaded by a
ClassLoader instance. Web applications still have to have libraries packaged in the
WEB-INF\lib directory and resource-adapter applications can have libraries bundled directly in the RAR file. Enterprise applications will need to package any libraries within the Web, EJB, or resource-adapter application that requires them. So how does the extension mechanism work with EJB applications? A JAR file can reference a dependent JAR file by adding a
Class-Path manifest attribute. The
Class-Path manifest attribute lists the relative URLs to search for utility libraries. Multiple URLs can be specified in a single
Class-Path entry and a single JAR file can contain multiple
Class-Path entries. For example, a JAR file might have:
Class-Path: log4j.jar xmlx.jar foo/bar/util.jar
NOTE: If you use the extension mechanism in a J2SE application, the
Class-Path manifest entry can reference directories, too. But for J2EE applications that are wholly contained within JAR files, the
Class-Path manifest entry can only reference other JAR files.
The extension mechanism is a nice capability, especially since it is designed to handle circular redundancies by creating a unified class path containing all dependencies in first parsed-based ordering. For example, if the first EJB application parsed is
EJB1.jar and it references:
Class-Path: jaxp.jar EJB2.jar xmlx.jar
A classloader will then parse EJB2.jar that references:
Class-Path: jaxp.jar EJB1.jar
The resulting "application" class path that a classloader would ultimately use would be:
Class-Path: jaxp.jar EJB2.jar xmlx.jar EJB1.jar
The manifest class path will definitely spur better modularity of J2EE packages in the future. Using this model, developers can employ a simple scheme for determining which EJBs should be packaged into a single JAR file and which should be packaged in separate JAR files:
- Identify an entity EJB that participates in a CMR relationship. Identify all entity EJBs that are reachable via CMR relationships from the source entity EJB. This graph of entity EJBs must be packaged into a single JAR application. Repeat this process for each unique graph of entity EJB relationships
- Package all remaining EJBs into separate JAR files.
- Analyze your business and technical requirements and "converge" multiple JAR files if it makes sense.
- Each EJB JAR file should list its dependencies using the manifest class path attribute, as described above. An intelligent classloader will resolve any circular or repeating dependencies.
The only limitation that developers are now faced with is locating an application server that fully supports this packaging capability. Developers will need to look for application servers that run in a 1.3 JDK and fully support section 8.1.2 of J2EE 1.3. Without this support, developers will need to fall back to one of the other, less-desirable solutions posted in this article. Happy packaging!
Tyler Jewell , Director, Technical Evangelism, BEA Systems Tyler oversees BEA's technology evangelism efforts that are focused on driving early adoption of strategic BEA technologies into the ISV and developer community.
Read more EJB 2 columns.
Return to ONJava.com.
Does JBoss version 3 and above support section 8.1.2 of J2EE 1.3
2004-12-07 21:56:37 MrGoldy [View]
2004-06-22 06:48:33 Johnny.A.V.A [View]
2003-11-11 01:42:54 anonymous2 [View]
Mobile Camcorder Playback problem
2004-08-19 01:52:18 mykhunza [View]
Mobile Camcorder Playback problem
2005-11-21 02:22:49 PatilJava [View]
2003-06-27 22:05:34 anonymous2 [View]
2003-02-20 11:44:11 anonymous2 [View]
utility classes and weblogic's handling of the manifest
2003-04-24 11:06:12 anonymous2 [View]
2003-01-27 01:01:09 anonymous2 [View]
Prb with <cmp-version> tag with J2EE 1.3 server
2003-01-27 01:04:34 anonymous2 [View]
2003-01-06 18:03:39 anonymous2 [View]
2002-09-25 10:31:49 anonymous2 [View]
classloader and manifest file
2003-03-07 02:56:02 src2001 [View]
2002-04-23 07:44:43 rajesh978 [View]
2001-11-16 08:09:23 timothywashington [View]
2001-11-07 16:04:59 fadlmusa1 [View]
2001-09-26 14:23:24 teunis [View]
2001-07-19 07:40:40 fmarchioni [View]