views:

37

answers:

1

I am trying to load some classes that are common to all the web applications of my ear in a java ee 5 application.

I tried to do this by putting the classes (not jar) in a) directory called "lib"

b) also specifying in application.xml's

   <module><java>lib/common.jar</java></module> 

and was not successful by either option a or b

but when I jarred the classes into common.jar, I was able to load the classes by method b)

  1. Do both these method need the classes to be jarred ?
  2. what is the difference between providing the classes via the above 2 methods ? why does it seem like there are two ways to specify loading common classes ?
+2  A: 

I'm not sure which application server is being referred to here, and the nature of the common.jar file. For now, I'll assume that the application server is any JEE 5 container, and that the common.jar file is a utility jar (and not an EJB or similar module).

The JEE 5 Platform Specification actually defines the manner in which library support is to be provided by containers:

A .ear file may contain a directory that contains libraries packaged in JAR files. The library-directory element of the .ear file’s deployment descriptor contains the name of this directory. If a library-directory element isn’t specified, or if the .ear file does not contain a deployment descriptor, the directory named lib is used. An empty library-directory element may be used to specify that there is no library directory. All files in this directory (but not subdirectories) with a .jar extension must be made available to all components packaged in the EAR file, including application clients. These libraries may reference other libraries, either bundled with the application or installed separately, using any of the techniques described herein.

This does not mean that method B is incorrect, it is the one to be used for application servers like JBoss 4, that did not support the library-directory element in application.xml. I believe, Glassfish also supports the lib directory concept without a corresponding library-directory element.

Coming back to the question, placing classes alone in a directory in the EAR file appears to be supported only in WebLogic Server via the APP-INF\classes structure (needless to say, this is not a platform standard). Hence, it is recommended to jar the common classes and use the application server supported mechanism to make these common classes available to other modules in the application.

Vineet Reynolds
So - without going into WL or appserver specific mechanisms, I cannot specify naked class files as shared ? It looks like, according to the javaee spec, I always have to jar my common shared classes to enable it to be picked up from lib dir or from the java module .... highly inconvenient...
unmaskableinterrupt
Is it inconvenient because you need to do it during development or in production? I can't imagine it being highly inconvenient for deployment in production. During development, you're better off using one of the IDE plugins (especially the ones for Eclipse) as they usually reference the exploded JARs.
Vineet Reynolds
For development- for various reasons I cannot use the eclipse plugins and have setup my project with exploded directory structure and symlinks to the eclipse output dirs. The plugin only provides a way to create a fake ear like structure for the appserver to pick it up anyway right ? Ultimately the app server is the one that has to pick up classes from the lib directory. How does it do that ? you think the plugin jars up the classes from eclipse so the appserver can access classes ?
unmaskableinterrupt
Unless I'm mistaken, the 'fake EAR' file constructed, will continue to have an exploded JAR file (even for common classes). It is the contents of the application.xml file that is of significance though - I'm currently unaware of the specifics, but I think Eclipse inserts directory file paths to the location of the exploded JARs.
Vineet Reynolds
looks like WL picks us classes from APPINF/classes just fine. If I want WL to pick up unjarred classes from a directory in a non appserver way, I guess I am out of luck. The <lib> tag in application.xml expects a jar so does the <module><java> tag...
unmaskableinterrupt