<!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.&#160; 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.&#160; Specifically:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&#160; // ...</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; final ClassLoader loader = Thread.currentThread().getContextClassLoader();</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; URL loginConfig = loader.getResource(...);</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; // ...</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;">&#160;</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;">&#160; 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.&#160; 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;">&#160;</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;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (method != null) {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final ClassLoader old = SecurityActions.setThreadContextClassLoader(mBeanInstance.getClass().getClassLoader());</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; method.invoke(mBeanInstance);</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } finally {</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SecurityActions.resetThreadContextClassLoader(old);</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Which appears to stash the TCCL at that point and explicictly set it to the MBean's ClassLoader.&#160; 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;">&#160;</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;">&#160;</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.&#160; 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.&#160; Is that incorrect?&#160; 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;">&#160;</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;">&#160;</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:&#160; ExactlyWatt.ear</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; Length&#160;&#160;&#160;&#160; Date&#160;&#160; Time&#160;&#160;&#160; Name</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"> --------&#160;&#160;&#160; ----&#160;&#160; ----&#160;&#160;&#160; ----</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0&#160; 09-25-12 09:33&#160;&#160; META-INF/</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; 106&#160; 09-25-12 09:33&#160;&#160; META-INF/MANIFEST.MF</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0&#160; 09-25-12 09:33&#160;&#160; lib/</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"> 11378038&#160; 09-25-12 09:33&#160;&#160; ExactlyWatt.war</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160; 55168&#160; 09-25-12 09:33&#160;&#160; 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;">&#160;&#160;&#160;&#160;&#160; 866&#160; 09-25-12 09:33&#160;&#160; 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;">&#160;&#160;&#160; 40161&#160; 09-25-12 09:33&#160;&#160; lib/ydoclet-runtime.jar</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; 568&#160; 09-25-12 09:32&#160;&#160; META-INF/application.xml</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160; 1137&#160; 09-21-12 15:12&#160;&#160; META-INF/exactlywatt-ds.xml</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160; 1050&#160; 09-24-12 15:26&#160;&#160; META-INF/jboss-service.xml</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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:&#160; lib/config.jar</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160; Length&#160;&#160;&#160;&#160; Date&#160;&#160; Time&#160;&#160;&#160; Name</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; --------&#160;&#160;&#160; ----&#160;&#160; ----&#160;&#160;&#160; ----</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 0&#160; 09-25-12 09:33&#160;&#160; META-INF/</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160; 106&#160; 09-25-12 09:33&#160;&#160; META-INF/MANIFEST.MF</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160; 936&#160; 06-23-11 13:22&#160;&#160; META-INF/login-config.xml</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; --------&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; -------</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; 1042&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 3 files</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&lt;server xmlns="urn:jboss:service:7.0"</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><span>&#160; 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>&#160; 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>"&gt;</span></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><strong>&#160; &lt;!-- Note this MBean deploys &amp; works properly.&#160; It's accessing files on-disk in standalone/configuration rather than trying to pull from classloader.&#160; --&gt;</strong><br/></span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;mbean code="ucs.jb4compat.SystemPropertiesService" name="jboss.util:type=Service,name=SystemProperties-ExactlyWatt"&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160; &lt;attribute name="URLList"&gt;configuration/exactlywatt.properties&lt;/attribute&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;/mbean&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;mbean code="ucs.jb4compat.DynamicLoginConfig" name="sample-app:service=DynamicLoginConfig,domain=ExactlyWatt"&gt;</span></p><p style="padding-left: 30px;"><strong style="font-family: courier new,courier;">&#160;&#160;&#160; &lt;!-- With or without "META-INF/" here makes no difference. --&gt;</strong></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160; &lt;attribute name="AuthConfig"&gt;<strong>META-INF/</strong>login-config.xml&lt;/attribute&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160; &lt;depends&gt;jboss.util:type=Service,name=SystemProperties-ExactlyWatt&lt;/depends&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;/mbean&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&lt;/server&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;"><span>&lt;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>&#160; 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>&#160; 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;">&#160; version="6"&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;description&gt;ExactlyWatt Jar Index&lt;/description&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;display-name&gt;ExactlyWatt&lt;/display-name&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;module&gt;&lt;ejb&gt;ExactlyWatt_ejb.jar&lt;/ejb&gt;&lt;/module&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;module&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160; &lt;web&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;web-uri&gt;ExactlyWatt.war&lt;/web-uri&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;context-root&gt;/ExactlyWatt&lt;/context-root&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160; &lt;/web&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&#160; &lt;/module&gt;</span></p><p style="padding-left: 30px;"><span style="font-family: courier new,courier;">&lt;/application&gt;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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.&#160; 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 &lt;module&gt;&lt;service&gt;config.sar&lt;/service&gt;&lt;/module&gt; and application.xml with &lt;module&gt;&lt;java&gt;config.sar&lt;/java&gt;&lt;/module&gt;, it makes no difference on any of this.&#160; 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>