Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDI Instances not found in JAR inside WEB-INF/lib

I have a maven JSF project with several modules which is deployed to Glassfish 3.1.2.2.

Structure of the resulting EAR:

|-- lib
|-- META-INF
|-- core-module.jar (packaged as ejbModule by maven)
|   |-- com
|   |   |-- ApplicationSettings.java
|   |   |-- Module.java (Module interface)
|   |   `-- ModuleCORE.java (implementation of Module interface)
|   `-- META-INF
|       `-- beans.xml
`-- presentation-module.war (packaged as warModule by maven)
    |-- WEB-INF
    |   |-- beans.xml
    |   `-- lib
    |       |-- jar-module.jar
    |       |   |-- com
    |       |   |   `-- ModuleEXT1.java (implementation of Module interface)
    |       |   `-- META-INF
    |       |       `-- beans.xml
    |       `-- another-jar-module.jar
    |           |-- com
    |           |   `-- ModuleEXT2.java (implementation of Module interface)
    |           `-- META-INF
    |               `-- beans.xml
    |-- images
    |-- css
    |-- js
    `-- listModules.xhtml

I have three modules:

  • core-module
  • ext1-module
  • ext2-module

The following interface exists in the EJB-Module:

//Module.java
public interface Module {
    public String getName();
}

Each module itself implements the interface and returns their name:

  • ModuleCORE.java
  • ModuleEXT1.java
  • ModuleEXT2.java

In the core-module there is the following bean that listModules.xhtml refers to in order to display the list of modules:

//ApplicationSettings.java
@ApplicationScoped
@Named
public class ApplicationSettings {
    @Inject
    @Any
    private Instance<Module> modules;

    public List<String> getModuleList() {
        List<String> result = new ArrayList<String>();
        for (Module module : modules) {
            result.add(module.getName());
        }
        return result;
    }
}

Now the problem is that only the implementation of the core-Module is in the list of Instances. The implementations of the modules inside WEB-INF/lib are not found although the respective META-INF/beans.xml exist.

Can someone explain to me why CDI cannot find all instances of the Module interface?

Sidenote: Other @Named beans from the JAR inside WEB-INF/lib are injectable/can be used in the xhtml files. So basically CDI is doing its job and thus is inspecting the directories.

like image 442
dertkw Avatar asked Nov 12 '22 17:11

dertkw


1 Answers

Generally speaking, using EARs with CDI has been considered tricky at best, fruitless at worse. If you don't have a hard requirement to use an EAR, if you can put core-module into your WEB-INF/lib you'll end up with the results you expect.

like image 197
John Ament Avatar answered Nov 15 '22 05:11

John Ament