JBoss Modules module.xml 中dependencies有export="true"配置,如下:
<dependencies> <module name="C" export="true" /> </dependencies>
假设我们有三个module:A,B,C 关系如下图:
本示例代码:https://github.com/kylinsoong/wildfly-architecture,根据前面软件安装及资料下载中gituhb安装部分获取示例代码通过如下命令编译:
cd wildfly-architecture/modules/export/ mvn clean dependency:copy-dependencies install cd dist ant
./test.sh
JBoss Module Export [A -> B -> C] C -> class org.jboss.modules.export.c.Cast B -> class org.jboss.modules.export.c.Cast A -> class org.jboss.modules.export.c.Cast
public void afirm() { new Baker().baker(); loadclass("A"); }
public void baker() { new Cast().cast(); loadclass("B"); }
public void cast(){ System.out.println("JBoss Module Export [A -> B -> C]"); loadclass("C"); }
private void loadclass(String flag) { try { Class cls = Class.forName("org.jboss.modules.export.c.Cast").newInstance().getClass(); System.out.println(flag + " -> " + cls); } catch (Exception e) { System.out.println(flag + " Error " + e.getMessage()); } }
<?xml version="1.0" encoding="UTF-8"?> <module xmlns="urn:jboss:module:1.1" name="B"> <resources> <resource-root path="B.jar" /> </resources> <dependencies> <module name="C" export="true" /> </dependencies> </module>
JBoss Module Export [A -> B -> C] C -> class org.jboss.modules.export.c.Cast B -> class org.jboss.modules.export.c.Cast A Error org.jboss.modules.export.c.Cast from [Module "A:main" from local module loader @1d09ad6 (finder: local module finder @655fb6 (roots: /home/kylin/work/project/wildfly-architecture/modules/export/dist/build/Test/modules,/home/kylin/work/project/wildfly-architecture/modules/export/dist/build/Test/modules/system/layers/base))]
export="true"是指是否将当前modle的依赖也加载到当前module。例如,A 依赖 B,B 依赖 C,但 B 依赖 C 的export="true",所以 A 在加载 B 时,也将 C 加载。