4 Replies Latest reply on Feb 26, 2008 11:11 AM by peterj

    how to package ear and lib, classloader issue

    javatwo

      I have an ear application with entity,business and web modules.


      <application ...>

      foo.par



      bar.ejb3




      <web-uri>baz.war</web-uri>
      <context-root>/</context-root>






      The .par, .ejb3 and war files use classes in common.jar. I put the common.jar under /server/default/lib.

      In the common.jar,

      String className = System.getProperty("FooClassName");
      Class.forName(className).newInstance();

      trying to instantiate the package.Foo that is defined in web module inside the ear file,

      throws a exception:

      java.lang.ClassNotFoundException: No ClassLoaders found for: package.Foo

      the package.Foo is application specific and can not be put into common.jar that is a common library. However the common lib needs to instantiate the application specific class.

      How to solve this issue?
      Thanks for any help.
      Dave

        • 1. Re: how to package ear and lib, classloader issue
          peterj

          Class defined in war files are in a different scope from classes defined elsewhere. Thus any attempt to instantiate class in a war from anywhere other than inside the war will fail.

          P.S. Use the code tags when posting XML content - select the content and click the Code button.

          • 2. Re: how to package ear and lib, classloader issue
            javatwo

            Hi Peter,
            thanks for your help.

            If I move the class package.Foo to foo.par entity module, the common.jar under server/default/lib can instantiate the class.

            But the package.Foo class needs to access classes defined in the web module, and throws
            java.lang.NoClassDefFoundError.

            Is there a way for entity module to access war module? or can I configure some classloader to make it work?

            Thanks
            Dave



            • 3. Re: how to package ear and lib, classloader issue
              javatwo

              Another question:

              how to package a lib jar into enitty par module and session ejb3 module?

              Thanks
              Dave

              • 4. Re: how to package ear and lib, classloader issue
                peterj

                The class scoping is according to the spec - as far as I know there is no way around it (though the scoping does appear to be broken in 5.0 beta4, but I would not rely on that - it should be fixed by GA).

                In general the scoping is such that all classes in server/xxx/lib and server/xxx/deploy (other than those in war files) can see each other, but all classes within war files are in their own scopes (though they can see the classes in lib and deploy, but not in other war files). There is an option to limit the scope of classes within containers within the deploy directory (for example, limit the scope of the classes within an ear, specifically so that you can package in the ear different versions of classes that appear elsewhere).