4 Replies Latest reply on Oct 10, 2008 5:23 PM by rrkulkarni

    Loading different versions of same jar in ear application

    rrkulkarni Newbie

      Env: JBoss 4.2.2 GA EJB 3 JDK 1.5.0.15

      I have a jar with version 0 inside ear in lib folder. It is available to all the web and ejb modules. If I want to use higher version in web module I simple put new jar in WEB-INF/lib folder and it works fine. I am unable to do the same for ejb module. If I put a different version of jar inside ejb module it will not be loaded by jboss. It will use the jar in ear/lib folder only. It loads jar in ejb module fine if I delete the jar in ear/lib folder.

      Is there a way I can use one version of jar in ear/lib folder and another version inside ejb module?

      I like the class loading scheme for web modules. It loads web module specific jars first without worrying about already loaded jars and if not found then it will look to the parent. Makes perfect sense. Web module can choose to use already existing version or use a new updated one with no effect on other modules.

      This does not work for ejb modules. It will first check if a jar is already loaded and use the same if alreday loaded. If it is not loaded then it will check if it exists in ejb module itself. It is forced to use the jar if it is loaded by classloader. It cannot use a better/different version of jar if it wants. So basically all ejb modules are forced to use the jar version in ear/lib folder.

      Is there a work around or am I simply missing something.

      Thanks a lot
      Ravi


        • 1. Re: Loading different versions of same jar in ear applicatio
          jaikiran pai Master

           

          "rrkulkarni" wrote:

          I like the class loading scheme for web modules. It loads web module specific jars first without worrying about already loaded jars and if not found then it will look to the parent. Makes perfect sense. Web module can choose to use already existing version or use a new updated one with no effect on other modules.


          That's because the spec mandates that each web module has its own classloader.


          "rrkulkarni" wrote:


          If I put a different version of jar inside ejb module it will not be loaded by jboss.



          Could you please explain as to what you mean by placing a jar "inside an ejb module"?

          When you place a jar inside the lib folder of EAR, it becomes available to the entire application.

          Are you sure that you want two different versions of a jar inside the same (EAR) application? I don't think what you are trying to do, would be possible.




          • 2. Re: Loading different versions of same jar in ear applicatio
            rrkulkarni Newbie

            Thanks for getting back to me on this issue.

            I meant literally putting the jar file inside TestEJB.jar. The idea was that EJB container will load the jar inside TestEJB.jar before looking in lib folder inside EAR.

            Trying to use two versions of same jar is exactly what I am trying to do. My EAR has lot of EJB modules some of which make use of earlier ( ancient) version of Castor which is in EAR/LIB folder. I am writing a new EJB that uses latter version of castor. I have written the code assuming later version of Castor. Now while testing I found out that earlier version of castor is stepping on my castor.jar which is inside my TestEJB.jar.

            If I replace the castor.jar in EAR/lib folder my ejb will work but many others which are using old version are failing. My code does not work with old version of castor.

            I was hoping to find some way of using two versions of jar in same EAR. I guess my only option is to rewrite my code using earlier version. I also thought of writing a custom classloader but am not sure if that will even work given that earlier version is already loaded by jboss.

            Thanks again
            Ravi

            • 3. Re: Loading different versions of same jar in ear applicatio
              Andrew Rubinger Master

              Is there anything preventing you from packaging two EARs, one for each version of Castor you need to support?

              I would not recommend ClassLoading hacks; this is a notion that you should be delegating out to the Container, and we're not exposing the internals to be altered.

              • 4. Re: Loading different versions of same jar in ear applicatio
                rrkulkarni Newbie

                That is a possibility. Only issue would be we already have 4 ears. If 4 is ok then 5 cannot be too bad. :-)

                Any way. Thanks for the suggestions. I probably will go with either a new ear file or back porting my code to previous version of castor depending on how long it will take me to back port the code.

                Thanks again
                Ravi