I'm having a problem running a simple web app. I have an EAR file with the following contents: utility.jar webApp.war /META-INF application.xml The utility.jar file contains common classes that can be used by any web application. The webApp.war file references classes contained in utility.jar, but when I try to access the web application, I get ClassNotFoundException's all over the place. I tried creating a /lib directory in the EAR and placed the utility.jar file in that directory thinking that it would be picked up by the EAR class loader, much in the same way WAR's work with /classes and /lib directories. Unfortunately, it doesn't work. Now, I found out that if I place a simple EJB in the EAR and specify the utility.jar in the EJB's manifest file, the web application works fine. Apparently the EJB forces the EAR class loader to find the utility.jar file which in turn makes it available to any WAR inside the EAR. But what if you have an EAR that doesn't contain EJB's? How do you make JAR files containing a common codebase available to the WAR's inside the EAR? I tried specifying a module in the EAR's application.xml file using the following format: <module> <java>utility.jar</java> </module> But this doesn't work either. Any ideas? Thanks, SAF
It's actually easy. Just add the utility Jar file to the manifest of your WAR file. By the way the same trick works in your EJB Jar files as well. This article by Tyler Jewell describes the solution in detail. Kyle
As an additional note, I spent a good couple of hours trying to figure out why I was getting ClassNotFoundExceptions and the like even after I had added a JAR file to a WAR file's manifest. The reason was that I had two copies of it in my EAR file - one in a JAR file and one in a JAR file in the WEB-INF/lib/ directory of the WAR. Basically the app server was loading the shared classes from the JAR in the EAR, which subsequently couldn't see any other classes in the WAR file because the WAR classloader sits "underneath" the EAR classloader. Makes sense but was a pain! :roll: There's another good explanation at http://www.theserverside.com/resources/article.jsp?l=J2EE-Deployment Simon
Joined: Jul 06, 2001
Originally posted by Kyle Brown: It's actually easy. Just add the utility Jar file to the manifest of your WAR file. By the way the same trick works in your EJB Jar files as well. This article by Tyler Jewell describes the solution in detail. Kyle
Ok, so create a /META-INF directory in the root of my WAR and add a CLASSPATH specification in it to reference JAR's in the EAR. How do you specify the path from the WAR to the EAR? Is it relative? In other words, should I specify the following in order for the WAR to know where to find the JAR in the EAR: Manifest-Version: 1.0 Class-Path: ../../utility.jar I'm just confused as to how to set up the paths in the WAR's manifest file. Thanks Kyle, SAF
subject: How to make utility JAR's in EAR's available to WAR's....