<HTML><BODY>Hi all,<br><br>I am posting the result of solution to make Weld work as JPMS auto module.<br><br>In this solution I use only module path. I manually create JPMS layer and add all modules<br>to it. For Weld I added the following modules:<br><br> <module file="cdi-api-2.0.jar"/><br> <module file="javax.annotation-api-1.3.2.jar"/><br> <module file="javax.inject-1.jar"/><br> <module file="javax.interceptor-api-1.2.jar"/><br> <module file="jboss-classfilewriter-1.2.2.Final.jar"/><br> <module file="jboss-logging-3.2.1.Final.jar"/><br> <module file="guava-18.0.jar"/><br> <module file="weld-se-core-3.0.4.Final.jar"/><br> <module file="weld-environment-common-3.0.4.Final.jar"/><br> <module file="weld-core-impl-3.0.4.Final.jar"/><br> <module file="weld-spi-3.0.SP3.jar"/><br> <module file="weld-api-3.0.SP3.jar"/><br> <module file="jandex-2.0.5.Final.jar"/><br><br>Note, that jandex is 2.0.5 but not 2.0.3 as 2.0.3 doesn't work well with java9. Besides Weld modules<br>I have two modules - in beanModule( here I have my cdi beans + beans.xml) and serverModule (here<br>I create Weld etc).<br><br>In serverModule I have the following code:<br><br>Weld builder = new Weld()<br> .property("org.jboss.weld.construction.relaxed", true)<br> .setClassLoader(this.getClass().getClassLoader())<br> .setResourceLoader(new ResourceLoaderImpl());<br>WeldContainer container = builder.initialize();<br>BeanManager bm = container.getBeanManager();<br><br>This is my ResourceLoaderImpl:<br><br>public class ResourceLoaderImpl implements ResourceLoader {<br><br> private static final String ERROR_LOADING_CLASS = "Error loading class ";<br><br> @Override<br> public Class<?> classForName(String name) {<br> try {<br> return Class.forName(name);<br> } catch (ClassNotFoundException e) {<br> throw new ResourceLoadingException(ERROR_LOADING_CLASS + name, e);<br> } catch (LinkageError e) {<br> throw new ResourceLoadingException(ERROR_LOADING_CLASS + name, e);<br> } catch (TypeNotPresentException e) {<br> throw new ResourceLoadingException(ERROR_LOADING_CLASS + name, e);<br> }<br> }<br><br> @Override<br> public URL getResource(String name) {<br> try {<br> Module module = this.getClass().getModule().getLayer().findModule("beanModule").orElse(null);<br> ModuleReference reference = getReference(module);<br> Optional<URI> uri = reference.open().find(name);<br> if (uri.isPresent()) {<br> return uri.get().toURL();<br> } else {<br> return null;<br> }<br> } catch (MalformedURLException ex) {<br> ex.printStackTrace();<br> } catch (IOException ex) {<br> ex.printStackTrace();<br> }<br> return null;<br> }<br><br> @Override<br> public Collection<URL> getResources(String name) {<br> List<URL> result = new ArrayList<>();<br> //HERE WE NEED MODULE ITERATION<br> URL url = this.getResource(name);<br> if (url != null) {<br> result.add(url);<br> }<br> return result;<br> }<br><br> @Override<br> public void cleanup() { }<br>}<br><br>In beanModule in module-info I open packages, that contains beans.<br><br>The solution WORKS, via BeanManager I can get whatever bean I need. The only problem is that I can't<br>understand what I should return in getResouce(String) if I have many modules - what module first I should<br>return? For example, when weld calls getResource("META-INF/beans.xml") - ?<br><br>It would be very interesting to to get some comments.<br>-- <br>Best regards, Alex<br></BODY></HTML>