Packaging libraries with EARs
January 31, 2011 Comments Off
Hong’s recent packaging response on the GlassFish Forum reminded me of other similar problems faced by GlassFish users.
When packaging applications in an EAR file, the library JARs need to be placed in the archive lib directory (jars at the archive root level are not added to the classpath and thus available from other EAR artifacts..
The library jars placed in the
"/lib" directory of the EAR (the directory name can be overridden in
application.xml) will be visible to all sub-modules (JARs, WARs, and RARs) with no further configuration. No need to add
Class-Path entries in the EAR manifest.
In the sub-modules, you can use
Class-Path entries to explicitly reference library JAR files you may need.
Of course you can also “install” those libraries in the GlassFish
"/lib" directory but you may run into other problems since they would be visible and shared from all applications.
GlassFish also offers a
asadmin deploy --libraries foo.jar option (something a good number of people end up using when looking for an equivalent to “shared libraries” offered by other containers).
Then of course, if you’re like most server-side Java developer you could probably put your application on a diet and remove a few of those JARs to use what’s already in the platform.