<!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/571439#571439">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"><span>What I have so far can be found at </span><a class="jive-link-external-small" href="https://github.com/kabir/jboss-as/commits/demos-test-embedded-cleaned" target="_blank">https://github.com/kabir/jboss-as/commits/demos-test-embedded-cleaned</a><span>. I still need to go through and add privileged actions etc. before this can be pushed, but some feedback before finalizing this would be great.</span></div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The embedded stuff can be used with either flat or modular classloading. I'll talk about flat first since that is the simplest.</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">To start up an embedded server you simply create an instance of org.jboss.as.embedded.FlatEmbeddedServer and start that up as shown in org.jboss.test.as.embedded.flat.RunServerTestCase in embedded/flat:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.setProperty("jboss.embedded.server.home", Utils.getASHome().getAbsolutePath());</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.setProperty("jboss.embedded.server.modules", new File(Utils.getASHome(), "modules").getAbsolutePath());</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; FlatEmbeddedServer server = new FlatEmbeddedServer();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; server.start();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServerModel model = server.getClient().getServerModel();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Assert.assertNotNull(model);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; } finally {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.clearProperty("jboss.embedded.server.home");</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.clearProperty("jboss.embedded.server.modules");</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; server.shutdown();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The thing I had to do here to get it to work is to take the jboss.embedded.server.modules location, and copy that to a new location replacing the module.xml for each module with:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;module xmlns="urn:jboss:module:1.0" name="org.jboss.logging"&gt;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; &lt;dependencies&gt;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;module name="system" export="true"/&gt;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; &lt;/dependencies&gt;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&lt;/module&gt;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">So every module delegates to the system classloader. If the default module loader could be swapped out somehow in jboss-modules, I could come up with a more elegant solution for this if deemed important. </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">To run using modular classloading you need two projects:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">1) The implementation which starts the server and does the useful stuff. It contains all the dependencies to be able to compile that. This can be found in testsuite/modular/impl and depends on the stuff from embedded/modular/server</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">2) The bootstrap which is used to construct the module loader seeing the as modules and additional modules created per test. This does not have the implementation on the classpath but loads this up via modules. The bootstrap lives in testsuite/modular/test and has a simple classpath just containing things needed to be able to load the classes to be able to construct the test modules with no dependencies on things that should be loaded up via modules (found in embedded/modular/bootstrap). </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The main way to run a test is shown in testsuite/modular/test/org.jboss.test.as.modular.demos.test.DemosTestCase:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@TestSetup(</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; implClass="org.jboss.test.as.modular.demos.impl.DemosTestImpl",</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; testModule="test.demos",</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; tcclModule="test.demos.tccl",</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; systemPropertyProvider=DemoSystemPropertyProvider.class,</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; modules= {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; @ModuleDef(</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; name="test.demos",</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; packages={@PackageResource(directory="${demo.impl.classes}", packages={"org.jboss.test.as.modular.demos.impl"})},</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jars=@JarResource (directory="${project.root}/demos/target", jar="jboss-as-demos.*(?&lt;!sources)\\.jar", expand=true),</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dependencies= {@Dependency("javaee.api"), @Dependency("org.hornetq"), @Dependency("org.jboss.as.messaging"), @Dependency("javax.jms.api")}),</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; @ModuleDef (</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; name="test.demos.tccl",</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dependencies= {@Dependency("org.jboss.logging"), @Dependency("test.demos")})</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@RunWith(ModularJunitTestRunner.class)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class DemosTestCase {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The ModularJunitTestRunner picks up @TestSetup and creates:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-a module called 'test.demos' with some classes from testsuite/impl project and the jar from the demos project. Since this is the same name as 'testModule' the dependencies needed to start a server are added automatically, but since we need access to some more classes to run the demos that have been ported so far some more are added using the 'dependencies'.</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-a module called 'test.demos.tccl' that is used as the TCCL when running each test (Shrinkwrap currently relies on TCCL)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ModularJunitTestRunner then loads up org.jboss.test.as.modular.demos.impl.DemosTestImpl from the test.demos module and runs that which contains the real tests:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">public class DemosTestImpl&#160; {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; static ModularEmbeddedServer starter = new ModularEmbeddedServer(getASHome());</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; @BeforeClass</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; public static void startServer() throws Exception {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; starter.start(JMSSubsystemElement.JMS_CF_BASE.append("InVmConnectionFactory").getCanonicalName());</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; @AfterClass</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; public static void stopServer() throws Exception {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; starter.shutdown();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; @Test</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; public void testSar() throws Exception {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; SarTestRunner runner = new SarTestRunner(starter);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; runner.test();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160; &#8230;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">}</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">testsuite/modular/test/org.jboss.test.as.modular.embedded.test.ModuleBuilderTestCase shows how to use the ModuleLoaderBuilder directly (not recommended) or the more friendly ModularEmbeddedServerBuilder for users who want to bootstrap an AS instance from their code.</div><div> </div><p><span>What I have so far can be found at </span><a class="jive-link-external-small" href="https://github.com/kabir/jboss-as/commits/demos-test-embedded-cleaned" target="_blank">https://github.com/kabir/jboss-as/commits/demos-test-embedded-cleaned</a><span>. I still need to go through and add privileged actions etc. before this can be pushed, but some feedback before finalizing this would be great.</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The embedded stuff can be used with either flat or modular classloading. I'll talk about flat first since that is the simplest.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To start up an embedded server you simply create an instance of org.jboss.as.embedded.FlatEmbeddedServer and start that up as shown in org.jboss.test.as.embedded.flat.RunServerTestCase in embedded/flat:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.setProperty("jboss.embedded.server.home", Utils.getASHome().getAbsolutePath());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.setProperty("jboss.embedded.server.modules", new File(Utils.getASHome(), "modules").getAbsolutePath());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; FlatEmbeddedServer server = new FlatEmbeddedServer();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; server.start();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServerModel model = server.getClient().getServerModel();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Assert.assertNotNull(model);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } finally {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.clearProperty("jboss.embedded.server.home");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.clearProperty("jboss.embedded.server.modules");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; server.shutdown();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The thing I had to do here to get it to work is to take the jboss.embedded.server.modules location, and copy that to a new location replacing the module.xml for each module with:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p><p>&lt;module xmlns="urn:jboss:module:1.0" name="org.jboss.logging"&gt;</p><p>&#160;&#160;&#160; &lt;dependencies&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;module name="system" export="true"/&gt;</p><p>&#160;&#160;&#160; &lt;/dependencies&gt;</p><p>&lt;/module&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So every module delegates to the system classloader. If the default module loader could be swapped out somehow in jboss-modules, I could come up with a more elegant solution for this if deemed important. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>To run using modular classloading you need two projects:</p><ol><li>The implementation which starts the server and does the useful stuff. It contains all the dependencies to be able to compile that. This can be found in testsuite/modular/impl and depends on the stuff from embedded/modular/server</li><li>The bootstrap which is used to construct the module loader seeing the as modules and additional modules created per test. This does not have the implementation on the classpath but loads this up via modules. The bootstrap lives in testsuite/modular/test and has a simple classpath just containing things needed to be able to load the classes to be able to construct the test modules with no dependencies on things that should be loaded up via modules (found in embedded/modular/bootstrap). </li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The main way to run a test is shown in testsuite/modular/test/org.jboss.test.as.modular.demos.test.DemosTestCase:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>@TestSetup(</p><p>&#160;&#160;&#160; implClass="org.jboss.test.as.modular.demos.impl.DemosTestImpl",</p><p>&#160;&#160;&#160; testModule="test.demos",</p><p>&#160;&#160;&#160; tcclModule="test.demos.tccl",</p><p>&#160;&#160;&#160; systemPropertyProvider=DemoSystemPropertyProvider.class,</p><p>&#160;&#160;&#160; modules= {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; @ModuleDef(</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; name="test.demos",</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; packages={@PackageResource(directory="${demo.impl.classes}", packages={"org.jboss.test.as.modular.demos.impl"})},</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jars=@JarResource (directory="${project.root}/demos/target", jar="jboss-as-demos.*(?&lt;!sources)\\.jar", expand=true),</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dependencies= {@Dependency("javaee.api"), @Dependency("org.hornetq"), @Dependency("org.jboss.as.messaging"), @Dependency("javax.jms.api")}),</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; @ModuleDef (</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; name="test.demos.tccl",</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dependencies= {@Dependency("org.jboss.logging"), @Dependency("test.demos")})</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>)</p><p>@RunWith(ModularJunitTestRunner.class)</p><p>public class DemosTestCase {</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The ModularJunitTestRunner picks up @TestSetup and creates:</p><p>-a module called 'test.demos' with some classes from testsuite/impl project and the jar from the demos project. Since this is the same name as 'testModule' the dependencies needed to start a server are added automatically, but since we need access to some more classes to run the demos that have been ported so far some more are added using the 'dependencies'.</p><p>-a module called 'test.demos.tccl' that is used as the TCCL when running each test (Shrinkwrap currently relies on TCCL)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ModularJunitTestRunner then loads up org.jboss.test.as.modular.demos.impl.DemosTestImpl from the test.demos module and runs that which contains the real tests:</p><p>public class DemosTestImpl&#160; {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; static ModularEmbeddedServer starter = new ModularEmbeddedServer(getASHome());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @BeforeClass</p><p>&#160;&#160;&#160; public static void startServer() throws Exception {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; starter.start(JMSSubsystemElement.JMS_CF_BASE.append("InVmConnectionFactory").getCanonicalName());</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @AfterClass</p><p>&#160;&#160;&#160; public static void stopServer() throws Exception {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; starter.shutdown();</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Test</p><p>&#160;&#160;&#160; public void testSar() throws Exception {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; SarTestRunner runner = new SarTestRunner(starter);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; runner.test();</p><p>&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; &#8230;</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>testsuite/modular/test/org.jboss.test.as.modular.embedded.test.ModuleBuilderTestCase shows how to use the ModuleLoaderBuilder directly (not recommended) or the more friendly ModularEmbeddedServerBuilder for users who want to bootstrap an AS instance from their code.</p><div> </div></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/571439#571439">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>