Search code examples
jakarta-eeejbearmanifest.mf

How to properly use Class-Path mechanism in Java EE 7 application modules


I'm curious about how to properly use Class-Path mechanism in portable Java EE 7 multimodule application.

Must EJB module reference 3rd party libraries, placed in lib folder of the EAR, in its MANIFEST.MF Class-Path?

To me, it looks like explicit references to them are not needed, because Java EE specification (EE.8.4.1 "Assembling a Java EE Application", item 3.e) states:

Make sure that each component in the application properly describes any dependencies it may have on other components in the application. A Java EE application should not assume that all components in the application will be available on the class path of the application at run time. Each component might be loaded into a separate class loader with a separate namespace. If the classes in a JAR file depend on classes in another JAR file, the first JAR file should reference the second JAR file using the ClassPath mechanism. A notable exception to this rule is JAR files located in the WEB-INF/lib directory of a web application. All such JAR files are included in the class path of the web application at runtime; explicit references to them using the Class-Path mechanism are not needed. Another exception to this rule is JAR files located in the library directory (usually named lib) in the application package.

But I found advises to add references to 3rd party libraries to Class-Path of EJB module, when I was googling this question. And this confuses me a little bit.

I'll appreciate any help!


Solution

  • Well it depends on the way your dependencies are loaded.

    if they are loaded at the ear level (shared between all ejb modules) you don't need to specify anything in the ejb-jar manifest (cf. Parent First delegation model), otherwise if you want your module dependencies to be specific to the module (and so isolated), you'll have to explicitly reference them in the manifest.

    here is a good article :http://www.developer.com/java/ejb/article.php/10931_3670496_2/Packaging-EJB-3-Applications.htm