I have this application which consists of EJB's, servlets and lots of utility classes. Now, I would like to deploy the EJB's into a JAR file, the servlets and utility classes into a WAR file and the JAR and WAR files into an EAR file.
Now, the EJB's use methods in the utility classes, but so do the servlets. Is there any way to deploy this project so that both the EJB's and the servlets have access to the utility classes WITHOUT these utility classes having to be included in both the JAR and the WAR file?
I have tried several different things, but they have all failed. If I include the utility classes in both the JAR and the WAR file, everyting works, but that's ugly and redundant and I don't like it at all ...
Any help greatly appreciated!
A J2EE Web application has a WEB-INF/lib directory in which utility classes residing in JAR files can be placed in order to be accessed by the Web application's servlets and other classes running in the context of a servlet. The extension mechanism for JDK 1.3 allows .jar files to declare dependencies upon other .jar files using a "Class-Path:" attribute in the manifest file. The Class-Path: attribute consists of a list of relative URLs that will be searched by the application server's classloader in order to find utility classes residing in directories and .jar files. This is an important improvement, since it allows multiple EJBs to reference one set of utility classes. With J2EE, the Class-Path: attribute will only work with .jar files.
Using a combination of the WEB-INF/lib directory and the Class-Path: attribute, you can intelligently distribute your application files by:
1) Placing classes that are shared by more than one Web application in a common .jar file and adding a reference to the .jar file in the Class-Path: list of the application's manifest file.
2) Adding references to EJB support libraries in the proper manifest Class-Path: list.
3) Placing utility .jar files for a Web application in the application's WEB-INF/lib directory.
Dig Deeper on Topics Archive
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.