aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes My EJB needs access to classes in WAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "My EJB needs access to classes in WAR" Watch "My EJB needs access to classes in WAR" New topic
Author

My EJB needs access to classes in WAR

Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
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.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
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.


    I think, therefore I exist -- Rene Descartes
    Maky Chopra
    Ranch Hand

    Joined: Apr 11, 2001
    Posts: 149
    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

    Joined: Feb 17, 2005
    Posts: 704

    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: My EJB needs access to classes in WAR