简体   繁体   中英

JBoss 7.x SAR archive class loading issue

I am trying to build a sar archive that contains an MXBean and deploy it in JBoss 7.

Until recently I had a problem referencing classes from other libraries in my MXBean class because JBoss wouldn't load those libraries no matter where in the SAR archive I'd put them.

I found out that one can configure the classpath of a SAR through the jboss-deployment-structure.xml file placed in META-INF. My version of this file looks like this:

<jboss-deployment-structure>
<deployment>
    <resources>
        <resource-root path="management.api.jar" />
    </resources>
</deployment>

Now the classes from the "management.api.jar" are loaded.

The problem I am now facing is the following: If the interface of the MXBean is stored in the management.api.jar and the class implementing it is directly in the SAR archive, then, when JBoss reads the jboss-service.xml and tries to create the mxbean it yields a ClassNotFoundException pointing to the interface (that is in the management.api.jar). Hence, although classes from the external jar are loaded ok (i tested this by actually invoking a method that referenced a class from the jar and it worked), it seems that when JBoss registers the bean, it doesn't go through the whole classpath as defined in the jboss-deployment-structure.xml.

I am currently stuck and I suspect this to be a bug in the way JBoss handles the class loading. If anyone knows a way around this (other than taking the interface out of the jar and putting it in the SAR archive directly, cause this will break the whole "api" idea) please let me know.

Thanks!

When I understand it right, the management api should be used in different projects and should be global in the server. A simple workaround can be to put your jar in the module-folder of your jboss. Therefor create a module.xml like this below and put it with your jar in a extra-folder main in the jboss7/modules/yourfolder. (In the module folder the jboss 7.1 stores all libs.)

  <!-- defines the name of your lib --> <module xmlns="urn:jboss:module:1.1" name="yourfolder"> <resources> <!-- the jar in your main folder--> <resource-root path="management.api.jar"/> <!-- Insert resources here --> </resources> <dependencies> ...dependencies of your api </dependencies> </module> 

Then you can load the dependency from your sar-jboss-deployment-structure by

  <dependencies> <module name="yourfolder" slot="main" export="true"/> </dependencies> 

The slot=main means that you use the the folder main, you can add different versions, like 1.1 and so on. Main is also the default slot, you can leave it out.

If your folder-structure goes into deep, simple define and include the modules like packages. In that way you can define api.jars in the jboss and reference it from several projects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM