I am building a JEE plugin architecture using wildfly (and jboss modules which included by wildfly core).
currently i got working loading xhtml from other deployed modules (core-web.war loads xhtml files from deployment.customers.jar
or any deployment.xmodule.jar
) thanks to Obtaining Facelets templates/files from an external filesystem or database and a "extension registry" i use to know which modules are available.
The problem arises when i try to use managed beans from those deployed modules, this because annotations are not scanned, i don't know if this is because i need a custom component on JSF, EL, Classpath, CDI or Jboss Module.
I am using Wildfly 10, JEE 7, primefaces 6.
whats the simplest way to get this working.
Some of my tries are:
i have read jboss modules documentation, i found a module dependencies can't be modified after module is initialized. But i found i can access any module programatically. for instance:
Module currentMod = org.jboss.modules.Module.getCallerModule(); Module otherModule = currentMod.getModuleLoader().loadModule(ModuleIdentifier.create("deployment.inmuebles-web.jar")); otherModule.getClassLoader().loadClass("co.hatit.enterprise.inmuebles.beans.InmueblesBean");
i have read CDI doc and it says i can listen lifecycle events such as type and bean discovery, but i'm not sure if this is what i need.
public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) { try { Field f = ClassLoader.class.getDeclaredField("classes"); f.setAccessible(true); //Get all classes from other module ClassLoader classLoader = org.jboss.modules.Module.getCallerModule().getModuleLoader() .loadModule(org.jboss.modules.ModuleIdentifier.create("deployment.customers-web.jar")) .getClassLoader(); List<Class> classes = (List<Class>) f.get(classLoader); for (Class<?> clazz : classes) { final AnnotatedType<?> annotatedType = beanManager.createAnnotatedType(clazz); bbd.addAnnotatedType(annotatedType); } } catch (Exception e) { e.printStackTrace(); } }
i also tried to build a custom el resolver, but it's not working.
public class PluginELResolver extends ELResolver { @Override public Object getValue(ELContext ctx, Object base, Object property) { return CDI.current().getBeanManager().getBeans("inmueblesBean"); } }