3 Replies Latest reply on Sep 15, 2009 9:56 AM by sammy Jenkis

    EAR lib precedence/ordering

    sammy Jenkis Newbie

      I have an .ear with several shared library jars in <ear root>/lib. I need to make sure a few of these jars take precedence so the classes in them override classes in other jars.

      Is there a way to do this reliably on JBoss 5.1?

        • 1. Re: EAR lib precedence/ordering
          Ales Justin Master

          Off the top of my head, I would say the only way to do this is to rewrite EARStructure class.
          I'll have a closer look tomorrow,
          providing some example if you still need it.

          • 2. Re: EAR lib precedence/ordering
            Ales Justin Master

             

            "alesj" wrote:
            Off the top of my head, I would say the only way to do this is to rewrite EARStructure class.
            I'll have a closer look tomorrow,
            providing some example if you still need it.

            This is the code that currently adds ear' lib/ contents to classpath:
             String libDir = appMetaData.getLibraryDirectory();
             if (libDir == null || libDir.length() > 0)
             {
             if (libDir == null)
             libDir = "lib";
            
             // Add the ear lib contents to the classpath
             if(trace)
             log.trace("Checking for ear lib directory: "+libDir);
             try
             {
             lib = file.getChild(libDir);
             if (lib != null)
             {
             if(trace)
             log.trace("Found ear lib directory: "+lib);
             List<VirtualFile> archives = lib.getChildren(earLibFilter);
             for (VirtualFile archive : archives)
             {
             addClassPath(structureContext, archive, true, true, context);
             try
             {
             // add any jars with persistence.xml as a deployment
             if (archive.getChild("META-INF/persistence.xml") != null)
             {
             log.trace(archive.getName() + " in ear lib directory has persistence units");
             if (structureContext.determineChildStructure(archive) == false)
             {
             throw new RuntimeException(archive.getName()
             + " in lib directory has persistence.xml but is not a recognized deployment, .ear: "
             + file.getName());
             }
             }
             else if (trace)
             log.trace(archive.getPathName() + " does not contain META-INF/persistence.xml");
            
             }
             catch(IOException e)
             {
             // TODO - should we throw this fwd?
             log.warn("Exception searching for META-INF/persistence.xml in " + archive.getPathName() + ", " + e);
             }
             }
             }
             else if (trace)
             log.trace("No lib directory in ear archive.");
             }
             catch (IOException e)
             {
             // TODO - should we throw this fwd?
             log.warn("Exception while searching for lib dir: " + e);
             }
             }
             else if (trace)
             {
             log.trace("Ignoring library directory, got empty library-directory element.");
             }
            


            What you need is ordering of archives before processing it.

            • 3. Re: EAR lib precedence/ordering
              sammy Jenkis Newbie

              Thanks a lot for the info Ales. I'll give this a try.