Search code examples
javajakarta-eecdiwildflyear

Valid project structure in EAR


I have an application packed in .ear file. This is the structure:

EmployeeManager
|---EmployeeManagerEJB.jar
    ---src/                 (1)
|---EmployeeManagerJSF.war/
    ---index.xhtml
    ---WEB-INF/
        ---classes/      (2)
        ---lib/
|---lib/
    ---EmployeeManagerIntegration.jar
        ---src/               (3)

I use CDI to inject to classes located in (2) EJBs which interfaces are in (3) and implementations are in (1). However CDI throws exception " Unsatisfied dependencies for type ...". I assume something is wrong with my EAR structure. What should I do to fix this thing up?


Solution

  • CDI does not work by default between sub-deployments as they do not use the same classloader.

    1. You could try placing your CDI beans in the EAR/lib folder this may work
    2. make sure all sub-deployments have beans.xml in them if they are using CDI
    3. there is no reason for this to be an EAR deployment, you can put both jars in WAR/lib and things will work fine
    4. You can define inter-sub-deployment dependencies by adding class-path values into meta-inf/manifest.mf (This is somewhat standard between containers, here's the wildfly example: https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly)
    5. Or you can rely on your container implementation and turn off sub-deployment isolation (For wildfly see the following: https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly)
    6. You could copy your CDI beans to each sub-deployment that use them