<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: Access EAR classpath from MBean in JBoss Module?
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/zbedell">Zachary Bedell</a> in <i>JBoss AS 7 Development</i> - <a href="https://community.jboss.org/message/761402#761402">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>The location of the jboss-service.xml doesn't appear to make a difference.  Step-debugging through the MBean's start() method, it looks like the TCCL is set in such a way that I don't have a chance of getting at my deployment's resources.  Specifically:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">public void start() throws Exception {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  // ...</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  final ClassLoader loader = Thread.currentThread().getContextClassLoader();</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  URL loginConfig = loader.getResource(...);</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  // ...</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">}<br/></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: arial,helvetica,sans-serif;">Inspecting loader at this point gives:</span></p><p><span style="font-family: arial,helvetica,sans-serif;">  ModuleClassLoader for Module "ucs.jb4compat:main" from local module loader @23e8f4e1 (roots: /opt/software/sag/sag_dev/modules)</span></p><p>IE the TCCL is the module's ClassLoader, not that of the EAR deployment.  To the best of my knowledge, I don't have any EAR classes available at that point from which I could grab an appropriate ClassLoader.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Looking up the stack a bit, I see:</p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">// org.jboss.as.service.AbstractService:</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">protected void invokeLifecycleMethod(final Method method) throws InvocationTargetException, IllegalAccessException {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">        if (method != null) {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">            final ClassLoader old = SecurityActions.setThreadContextClassLoader(mBeanInstance.getClass().getClassLoader());</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">            try {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">                method.invoke(mBeanInstance);</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">            } finally {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">                SecurityActions.resetThreadContextClassLoader(old);</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">            }</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">        }</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">    }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Which appears to stash the TCCL at that point and explicictly set it to the MBean's ClassLoader.  The stashed TCCL (old) at that point is "ModuleClassLoader for Module "org.jboss.as.sar:main" from local module loader @23e8f4e1 (roots: /opt/software/sag/sag_dev/modules)".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I've tried repackaging my resource (login-config.xml) inside the ear as ear//lib/config.sar//META-INF/login-config.xml as well as ear//lib/config.sar//login-config.xml, but none of the ClassLoader's I have available within the MBean's start() method are anything related to my EAR or its contents.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>On a side note, I realize root-of EAR isn't expected to be in Classpath per EE spec, but I thought that contents of EAR/META-INF should be.  So in this case EAR/META-INF/login-config.xml would be equally accessible as EAR/lib/config.jar//META-INF/login-config.xml, assuming I had a ClassLoader with a view of the EAR.  Is that incorrect?  Granted the distinction is moot unless I can find an appropriate ClassLoader to pull from.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Just by way of structure, here's what I'm working with at the moment:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The EAR:</p><p><span style="font-family: arial,helvetica,sans-serif;">/Work/ExactlyWatt/java/dist/server/deployments $ unzip -l ExactlyWatt.ear </span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">Archive:  ExactlyWatt.ear</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  Length     Date   Time    Name</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"> --------    ----   ----    ----</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">        0  09-25-12 09:33   META-INF/</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">      106  09-25-12 09:33   META-INF/MANIFEST.MF</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">        0  09-25-12 09:33   lib/</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"> 11378038  09-25-12 09:33   ExactlyWatt.war</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">    55168  09-25-12 09:33   ExactlyWatt_ejb.jar</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">...</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">      866  09-25-12 09:33   lib/config.jar (See below)</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">...</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">    40161  09-25-12 09:33   lib/ydoclet-runtime.jar</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">      568  09-25-12 09:32   META-INF/application.xml</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">     1137  09-21-12 15:12   META-INF/exactlywatt-ds.xml</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">     1050  09-24-12 15:26   META-INF/jboss-service.xml</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>config.jar within EAR/lib: </p><p><span style="font-family: arial,helvetica,sans-serif;">/Work/ExactlyWatt/java/dist/server/deployments/ear $ unzip -l lib/config.jar </span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"> Archive:  lib/config.jar</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">   Length     Date   Time    Name</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  --------    ----   ----    ----</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">         0  09-25-12 09:33   META-INF/</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">       106  09-25-12 09:33   META-INF/MANIFEST.MF</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">       936  06-23-11 13:22   META-INF/login-config.xml</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  --------                   -------</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">      1042                   3 files</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>EAR/META-INF/jboss-service.xml:</p><p><span style="font-family: arial,helvetica,sans-serif;">/Work/ExactlyWatt/java/dist/server/deployments/ear $ cat META-INF/jboss-service.xml </span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><?xml version="1.0" encoding="UTF-8"?></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><server xmlns="urn:jboss:service:7.0"</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><span>  xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"</span></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><span>  xsi:schemaLocation="urn:jboss:service:7.0 </span><a class="jive-link-external-small" href="http://ucmsload.courtnet.org/dtds/jb7/jboss-service_7_0.xsd" target="_blank">http://ucmsload.courtnet.org/dtds/jb7/jboss-service_7_0.xsd</a><span>"></span></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><strong>  <!-- Note this MBean deploys & works properly.  It's accessing files on-disk in standalone/configuration rather than trying to pull from classloader.  --></strong><br/></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  <mbean code="ucs.jb4compat.SystemPropertiesService" name="jboss.util:type=Service,name=SystemProperties-ExactlyWatt"></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">    <attribute name="URLList">configuration/exactlywatt.properties</attribute></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  </mbean></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  <mbean code="ucs.jb4compat.DynamicLoginConfig" name="sample-app:service=DynamicLoginConfig,domain=ExactlyWatt"></span></p><p style="padding-left: 30px;"><strong style="font-family: courier new,courier;">    <!-- With or without "META-INF/" here makes no difference. --></strong></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">    <attribute name="AuthConfig"><strong>META-INF/</strong>login-config.xml</attribute></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">    <depends>jboss.util:type=Service,name=SystemProperties-ExactlyWatt</depends></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  </mbean></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"></server></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>/Work/ExactlyWatt/java/dist/server/deployments/ear $ cat META-INF/application.xml </p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><?xml version="1.0" encoding="UTF-8"?></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><span><application xmlns="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span>" </span></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><span>  xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>" </span></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><span>  xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span> </span><a class="jive-link-external-small" href="http://" target="_blank">http://</a></span><span style="font-family: courier new,courier;">ucmsload.courtnet.org/dtds</span><span style="font-family: courier new,courier;">/javaee/application_6.xsd" </span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  version="6"></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  <description>ExactlyWatt Jar Index</description></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  <display-name>ExactlyWatt</display-name></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  <module><ejb>ExactlyWatt_ejb.jar</ejb></module></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  <module></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">      <web></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">         <web-uri>ExactlyWatt.war</web-uri></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">         <context-root>/ExactlyWatt</context-root></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">       </web></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">  </module></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"></application></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;"><span style="font-family: arial,helvetica,sans-serif;">Note this particular attempt has jboss-service.xml directly in EAR//META-INF without a SAR file to wrap it.  If I change things to put jboss-service.xml inside EAR//config.sar//META-INF and add EAR//META-INF/jboss-app.xml with a <module><service>config.sar</service></module> and application.xml with <module><java>config.sar</java></module>, it makes no difference on any of this.  I still get the module's ClassLoader for TCCL in the MBean's start() method and have no access to the EAR deployment's contents.</span><br/></span></p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/761402#761402">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS 7 Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>