0 Replies Latest reply on Mar 12, 2016 7:07 AM by Nicolas Mundbrod

    Problem with classloading in EJB module packaged in EAR

    Nicolas Mundbrod Newbie

      Hi

      I'm currently developing a prototype that relies in Java EE 7. Maven is used for dependency management and its plugin maven-ear-plugin for the final build of an EAR. The latter is then deployed on a wildfly 10.0 application server.

       

      The project structure is as follows (simplified):

       

      - controler-api

      - controler-impl

      - model-api

      - model-impl

      - system-parent (maven parent package)

      - system-ear (to generate ear)

      - view-webapp

       

      The EAR consists of the two ejb3 modules "controler-impl" and "model-impl", as well as the web app "view-webapp". The maven-ear-plugin is configured accordingly:

       

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-ear-plugin</artifactId>
          <configuration>
              <defaultLibBundleDir>lib</defaultLibBundleDir>
              <generatedDescriptorLocation>META-INF</generatedDescriptorLocation>
              <modules>
                  <ejbModule>
                      <groupId>com.domain.abc</groupId>
                      <artifactId>model-impl</artifactId>
                  </ejbModule>
                  <ejbModule>
                      <groupId>com.domain.abc</groupId>
                      <artifactId>controler-impl</artifactId>
                  </ejbModule>
                   <webModule>
                      <groupId>com.domain.abc</groupId>
                      <artifactId>view-webapp</artifactId>
                      <contextRoot>/myapp</contextRoot>
                  </webModule>
              </modules>
          </configuration>
      </plugin>
      
      
      

       

      So far, everything has worked out well and the prototype is already in decent state.

       

      However, I have been facing a complicated problem for some days I cannot cope with:

       

      In the controler-impl, I want to use reflections (org.reflections) to determine classes that have been enriched with a specific annotation. Hence, I added the corresponding dependency and the jar reflections-0.9.10.jar is stored in the lib folder of the EAR correctly. But at run time, I always encounter a ClassNotFoundException showing me that the class loader in the ejb module controler-impl is not able to find the classes in reflections-0.9.10.jar. For debugging, I went through the class loader hierarchy and checked which packages and classes are available for them.

       

      I found three class loaders:

       

      1) ModuleClassLoader

          |

      2) AppClassLoader

          |

      3) ExtClassLoader

       

      None of them are able to access the classes in reflections-0.9.10.jar deposited in the central EAR lib folder. This is weird as I expected this key folder to be accessible by the all ear modules.

       

      Of course, I looked for existing solutions in the web. For instance, I found the following article explaining the class loader hierarchy/separation in more details.

       

      Packaging EJB 3 Applications - Developer.com

       

      Based on Table 2 in this article, I assumed that I have to add a manifest file in the ejb module. Of course, I tried this by changing configuration of the maven-ear-plugin or even adding the maven-ejb-plugin to the modules. But I always encounter the error "Class Path [...] in [...] does not point to a valid jar for a Class-Path reference" and the basic problem of the missing reference to the EAR lib folder still exists.

       

      I guess that I likely have to configure the maven-ear-plugin and/or maven-ejb-plugin better (whatever that means) - does anybody have an idea how to do that? Or did I miss something important regarding Wildfly (10)?

       

      Thanks a lot

       

      Nicolas