1 回答

TA貢獻1868條經驗 獲得超4個贊
如您所知,Wildfly 具有模塊化的類加載結構。每個模塊都有自己的類加載器。類類型相同是不夠的。在類加載器中必須相同。在JBoss 文檔中:
WildFly 的類加載基于必須定義對其他模塊的顯式依賴項的模塊。WildFly 中的部署也是模塊,并且無法訪問在應用程序服務器中的 jar 中定義的類,除非定義了對這些類的顯式依賴。
您可以創建自定義模塊并在此模塊中提供 .ears 加載 jar。在$JBOSS_HOME/modules/com/example/main/中創建module.xml文件,將要加載的 jar 名稱寫入module.xml。
<module xmlns="urn:jboss:module:1.5" name="com.example">
<resources>
? ? <resource-root path="sample.jar"/>
</resources>
將jar復制到module.xml所在路徑。
+-----com
? ? ?+-----example
? ? ? ? ? ?+-----main
? ? ? ? ? ? ? ? ?module.xml
? ? ? ? ? ? ? ? ?sample.jar
在 .ears 中創建部署描述符(jboss-deployment-structure.xml)并將您的模塊添加到此文件中。
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
? ? <dependencies>
? ? ? ? <module name="com.example" export="true" />
? ? </dependencies>
</deployment>
</jboss-deployment-structure>
所以,Jar 的類加載器是相同的。
添加回答
舉報