<!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="http://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: Embedded AS
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/kabir.khan%40jboss.com">Kabir Khan</a> in <i>JBoss AS7 Development</i> - <a href="http://community.jboss.org/message/571745#571745">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I don't think you can change the classpath of an already running java program, I tried this</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>projectA has class A</p><p>projectB has class B and Main</p><p>None of the projects import each other</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #a1006a;"><strong style="font-weight: bold;">public</strong> <strong style="font-weight: bold;">class</strong> Main {</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">&#160;&#160;&#160; <strong style="font-weight: bold;">public</strong> <strong style="font-weight: bold;">static</strong> <strong style="font-weight: bold;">void</strong> main(String[] args) <strong style="font-weight: bold;">throws</strong> Exception {</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.<em style="font-style: italic;">out</em>.println(Main.<strong style="font-weight: bold;">class</strong>.getResource("/"));</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #5b00ff;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.<em style="font-style: italic;">setProperty</em>("java.class.path", "/Users/kabir/sourcecontrol/jboss-as7/eclipse/projectA/bin/");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.<em style="font-style: italic;">out</em>.println(Class.<em style="font-style: italic;">forName</em>("B"));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.<em style="font-style: italic;">out</em>.println("Test");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Class.<em style="font-style: italic;">forName</em>("A1");</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">&#160;&#160;&#160; }</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">}</p><div> </div><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>This shows this output: </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">file:/Users/kabir/sourcecontrol/jboss-as7/eclipse/projectB/bin/</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">class B</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier;">Test</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #220099;">Exception in thread "main" java.lang.ClassNotFoundException: A1</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at java.net.URLClassLoader$1.run(URLClassLoader.java:202)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at java.security.AccessController.doPrivileged(Native Method)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at java.net.URLClassLoader.findClass(URLClassLoader.java:190)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at java.lang.ClassLoader.loadClass(ClassLoader.java:307)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at java.lang.ClassLoader.loadClass(ClassLoader.java:248)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at java.lang.Class.forName0(Native Method)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at java.lang.Class.forName(Class.java:169)</p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Courier; color: #ff0000;">at Main.main(Main.java:37)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So the write to java.class.path has no effect, the system classloader probably only reads that once on startup.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>If we want to only have one test project for this and control the app classpath I see the following options:</p><p>1) Have the test runner start another process with the minimal classpath and modules, I guess this would be something similar to what ant/maven does when running forked tests</p><p>2) jboss-modules makes it possible to configure the default ModuleLoader so we can do something more clever there such as specifying which packages should never be loaded from the system classpath even if they exit in both system and modules.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I prefer 2) which is needed for the flat embedded case anyway, but daren't start changing that on a whim :-) I can play with 1) for now and see if that gets me anywhere</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/571745#571745">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS7 Development at <a href="http://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>