users@glassfish.java.net

Re: GlassFish 3.1 Classloader Question

From: Hong Zhang <hong.hz.zhang_at_oracle.com>
Date: Mon, 06 Jun 2011 14:38:10 -0400

Hi, Chris
>
> I don't see anything about class-path in the ee6 tutorial, so I'm not
> sure
> where to look for documentation on this...
See Java EE 6 spec EE.8.2.1Bundled Libraries (I will copy/paste the
relevant sections at the end of the email).
> So the class-path entry has to exist in the manifest for the library
> jar that
> does the "forName"?
This is not the only way, but you basically have to make sure the
referenced class is visible to the class that's referencing it.
> So would this mean I have to do some jar-hacking while
> packaging the ear to modify the loading jar to refer to the location
> of the
> loaded class? What should the class-path entry look like?
It's not common that a library class is dependent on a class packaged in
a component jar (and that is not part of the EE spec requirement). If
the referencing class is a true library class that needs to be shared
across all the modules, can you package the referenced class into that
library jar as well? In this packaging, the referenced class is still
visible to the war. Or if that referencing class is only needed for the
war, package the referencing class into war instead?
>
> I'm inferring the packaged structure should include something like this:
>
> * App
> * War
> * WEB-INF
> * classes (which includes class to be loaded using "forName"
> in the
> loading.jar below)
> * ...
>
>
> * lib
> * loading.jar (with manifest modified with class-path:
> War/WEB-INF/classes)
> * ...
>
>
>
> Is there a NetBeans project setting to simplify this?
I am not aware of any magic attribute here, but others could chime in ;-)

If it's possible to repackage as I suggested earlier in the email, it
will be pretty straightforward.
>
> PS: This (or something very similar) seems to be discussed
> here: http://hanscappelle.blogspot.com/2010/07/ear-deployment-on-glassfish-3-vs.html
>
>
No, that's different. That's talking about how to make library jars
visible to the component classes and here you want to make the component
classes visible to library jars.

- Hong


Quoted from EE 6 spec
===================
EE.8.2.1Bundled Libraries
Libraries bundled with an application may be referenced in the following
ways:
1.A JAR format file (such as a .jar file, .war file, or .rar file) may
reference a .jar file or directory by naming the referenced .jar file or
directory in a Class-Path header in the referencing JAR file’s Manifest
file. The referenced .jar file or directory is named using a URL
relative to the URL of the referencing JAR file. The Manifest file is
named META-INF/MANIFEST.MF in the JAR file. The Class-Path entry in the
Manifest file is of the form
Class-Path: list-of-jar-files-or-directories-separated-by-spaces
(See the JAR File Specification for important details and limitations of
the syntax of Class-Path headers.) The Java EE deployment tools must
process all such referenced files and directories when processing a Java
EE module. Any deployment descriptors in referenced .jar files must be
ignored when processing the referencing .jar file. The deployment tool
must install the .jar files and directories in a way that preserves the
relative references between the files. Typically this is done by
installing the .jar files into a directory hierarchy that matches the
original application directory hierarchy. All referenced .jar files or
directories must appear in the logical class path of the referencing JAR
files at runtime.
Only JAR format files or directories containing class files or resources
to be loaded directly by a standard class loader should be the target of
a Class-Path reference; such files are always named with a .jar
extension. Top level JAR files that are processed by a deployment tool
should not contain Class-Path entries; such entries would, by
definition, reference other files external to the deployment unit. A
deployment tool is not required to process such external references.
..
3.A web application may include libraries in the WEB-INF/lib directory.
See the Servlet specification for details. These libraries may reference
other libraries, either bundled with the application or installed
separately, using any of the techniques described herein.