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:
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With