Use library-directory in JavaEE 5 apps

Starting from JavaEE 5, you can specify a directory inside the an EAR file to hold jar files that can be used by all modules of that EAR. For example, if you've built an EAR called hello.ear:

The content of META-INF/application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="5"



All classes and resources in all jar files under shared directory (e.g., util-1.jar, util-2.jar) are accessible to hello-ejb.jar and hello.war. For instance, you may choose to put hello-ejb's business interfaces, component interfaces and home interfaces in util-1.jar, to avoid duplicates in ejb jar and war.

Better yet, you don't even need to have an application.xml to use this mechanism. Recall that all descriptors are optional in JavaEE 5. The default library-directory is a directory named lib inside the EAR. You just put your shared jar files here and they will be automatically made accessible for all components. However, these files do need to use *.jar extension.


Anonymous said...

thanks for the info

Anonymous said...

Nice one. How to achieve shared library concept in previous versions of J2EE?

javahowto said...

Q: How to achieve shared library concept in previous versions of J2EE?

A: Use Class-Path entries in MANIFEST.MF in your WAR, ejb-jar, or application client jar files. For example:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
Class-Path: commons-foo.jar

This is the layout of the EAR file:


Ant task jar or war has attributes and subelements that let you customize MANIFEST.MF. So usually no need to hand craft one.

shared folder protect said...

It really helps me. thank you.

Unknown said...

Great and Useful Article.

Online Java Training

Java Online Training India

Java Online Course

Java EE course

Java EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Course in Chennai

Java Online Training India

eMexoT said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

Internet Of Things training in electronic city

rohini said...

Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.
apple iphone service center in chennai | apple ipad service center in chennai | apple iphone service center in chennai | | Mac service center in chennai

Anjali said...

I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this Salesforce Training who are providing certification and job assistance. Salesforce training in Noida