• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to make utility JAR's in EAR's available to WAR's....

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't touch me. And dont' touch this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic