• 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

My EJB needs access to classes in WAR

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All,

I have an EAR deployed on a JRun server on Windows. Here's the file structure:



Now, I have a MBD that onMessage() needs to instanitate an object whose classdef is in the MyWar/WEB-INF/classes/com/me/util/MyObj

SO I say MyObj obj = new MyObj();

And i wind up with classnotfound exception.

I looked around and found an article saying that I could use the Class-Path attributes in the MANIFEST.MF but this did not help me.

Link to article: http://livedocs.macromedia.com/jrun/4/Assembly_and_Deployment_Guide/descriptors7.htm

Any help will be appreciated. Thanks in advance.
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maky,

Please review your container�s class loading architecture first (it differs from container to container). WebLogic for example, creates three class loaders for each ear: a system class loader (that loads classes from the system classpath) an application clasloader (loads the war) and an ejb classloader that loads the EJB(s). They have a parent child relationship like this:

System CL -> App CL -> EJB CL.

If a class needs to be loaded, each CL asks its parent first to load the class. If none of its parents can load the class then the CL will try loading the class by itself. If the class is not found a ClassNotFoundException is thrown. You must remark three things:
  • Every parent can load all classes from its children but not vice versa. What I mean is that web components can view EJB components (so you can look up EJBs from within your JSPs) but it won�t work the other way around (an EJB cannot locate a servlet class).
  • If two different versions of the same class are loaded, the one loaded by the most-parent CL has precedence. For example, if you pack a utility class in your war but you forgot to remove an older version of the same class form the system classpath, you might encounter a very subtle bug, because your application is actually using the older version.
  • There is no mention about loading common libraries. And here there is when the manifest files come to the picture.


  • And if you have already red up to this point, you probably understood that what you�re trying to do is against all odds. You try to violate the second rule, accessing a class from one child (EJB) to its parent (Web App). In order to avoid this you might consider a more common approach: pack common classes in a common library and then update the manifest file to look for that library.
    Regards.
     
    Maky Chopra
    Ranch Hand
    Posts: 149
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks Valentine,

    I know that the EJB container won't find my WEB-INF/classes through it's classloader. It is very difficult for me to break up the common stuff into a separate jar which is why I'm trying to get the Ejb Classloader to load the extraneous classes by hard wiring into the manifest.

    Questions:

    1. Are you saying that by using the manifest, I will not be able to load the classes and jars from WEB-INF ?

    2. If so, where in my directory structure would I place the common jars and how would my manifest help in loading them?

    3. Does the manifest have to reside in a actual jar file or can in reside in the META-INF folder of the exploded Ejb jar folder?


    Thanks for your help.
     
    Valentin Tanase
    Ranch Hand
    Posts: 704
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    1. Are you saying that by using the manifest, I will not be able to load the classes and jars from WEB-INF ?


    No. What I�m saying is that I�ve never tried anything like this before and therefore I don�t know whether it works or not. My guess is that it should work if you provide the correct path, but again I�m not sure. What I�m sure though is that using a common library will definitely work since I�m doing this every day. The uncertainty though is even higher because you use a technology (I mean the container here) that could implement the class loading in a very independent manner ant it might not work whatsoever. So try for a while using the manifest and if it doesn�t work you might consider taking another approach.


    2. If so, where in my directory structure would I place the common jars and how would my manifest help in loading them?


    You can place the common.jar library in the root like any other war or jar you have. In all your manifest files (from war to jar) add a line like this

    Class-Path: iText.jar commons-collections.jar xalan.jar commons-lang.j
    ar common.jar Facade_EJB.jar (this is an extras from one of our war/jar).


    3. Does the manifest have to reside in a actual jar file or can in reside in the META-INF folder of the exploded Ejb jar folder?


    This I believe, depends whether you use an archive to deploy your application, or you deploy it in the exploded format (which you use only for development I hope). In that case it is as intuitive as you might expect: whatever works archived must work exploded and vice versa.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic