<!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;">
    EJB 3.1 Embeddable
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/wolfc">Carlo de Wolf</a> in <i>EJB3</i> - <a href="http://community.jboss.org/docs/DOC-9618">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><h2><span>EJB 3.1 Embeddable prototype</span></h2><p>This page reflects the current state of the JBoss EJB 3.1 Embeddable prototype.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The JBoss EJB 3.1 Embeddable prototype is not JBoss Embedded or the old EJB 3 Embedded. The old EJB 3 Embedded was actually a preview of what could be achieved with JBoss MicroContainer. It is better to think of it as a preview of JBoss AS 5.0. Later on it was renamed to JBoss Embedded.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Meanwhile for JBoss AS 6 a new <a class="jive-link-anchor-small">JBoss Embedded AS</a> implementation has been made, which enables JBoss AS 6 to be booted within a JVM. Using this facility a new standalone prototype has been created.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The goal of JBoss EJB 3.1 Embeddable is to have a standalone version of EJB 3 working according to the specifications in EJB 3.1 and fully compatible with the version going into JBoss AS.</p><h3><span>How to use in your project</span></h3><p>You can use jboss-ejb3-embedded-standalone either from Maven or using the jar directly in your favorite IDE/build/test-runner tool.</p><h4>Maven</h4><p>To get access to the latest Embeddable artifacts you must enable the JBoss Maven repositories either in your settings.xml or in your pom.xml. As an example I've pasted a pom.xml here:</p><pre class="jive-pre"><code class="jive-code">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
&#160;&#160; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
&#160;&#160; &lt;groupId&gt;org.jboss.beach.ejb3&lt;/groupId&gt;
&#160;&#160; &lt;artifactId&gt;test-embedded&lt;/artifactId&gt;
&#160;&#160; &lt;name&gt;test-embedded&lt;/name&gt;
&#160;&#160; &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&#160;&#160; &lt;description/&gt;

&#160;&#160; &lt;repositories&gt;
&#160;&#160;&#160;&#160;&#160; &lt;repository&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;id&gt;jboss-public-repository-group&lt;/id&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;name&gt;JBoss Public Maven Repository Group&lt;/name&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;url&gt;https://repository.jboss.org/nexus/content/groups/public-jboss/&lt;/url&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;releases&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;enabled&gt;true&lt;/enabled&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/releases&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;snapshots&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;enabled&gt;true&lt;/enabled&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/snapshots&gt;
&#160;&#160;&#160;&#160;&#160; &lt;/repository&gt;
&#160;&#160; &lt;/repositories&gt;

&#160;&#160; &lt;build&gt;
&#160;&#160;&#160;&#160;&#160; &lt;plugins&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;plugin&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;configuration&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;source&gt;1.6&lt;/source&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;target&gt;1.6&lt;/target&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/configuration&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/plugin&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;plugin&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;version&gt;2.6&lt;/version&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;configuration&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;argLine&gt;-Djboss.home=${JBOSS_HOME} -Xmx512m -XX:MaxPermSize=256m -Djava.endorsed.dirs=${JBOSS_HOME}/lib/endorsed&lt;/argLine&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/configuration&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;executions&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;execution&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;goals&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;goal&gt;integration-test&lt;/goal&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;goal&gt;verify&lt;/goal&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/goals&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/execution&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/executions&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/plugin&gt;
&#160;&#160;&#160;&#160;&#160; &lt;/plugins&gt;
&#160;&#160; &lt;/build&gt;
&#160;&#160; 
&#160;&#160; &lt;dependencies&gt;
&#160;&#160;&#160;&#160;&#160; &lt;dependency&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;groupId&gt;org.jboss.ejb3.embedded&lt;/groupId&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;artifactId&gt;jboss-ejb3-embedded-standalone&lt;/artifactId&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;version&gt;1.0.0-alpha-2&lt;/version&gt;
&#160;&#160;&#160;&#160;&#160; &lt;/dependency&gt;
&#160;&#160;&#160;&#160;&#160; &lt;dependency&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;groupId&gt;junit&lt;/groupId&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;artifactId&gt;junit&lt;/artifactId&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;version&gt;[4,)&lt;/version&gt;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;scope&gt;test&lt;/scope&gt;
&#160;&#160;&#160;&#160;&#160; &lt;/dependency&gt;
&#160;&#160; &lt;/dependencies&gt;
&lt;/project&gt;</code></pre><h4>Jar usage</h4><p>The jboss-ejb3-embedded-standalone jar is located in $JBOSS_HOME/client/jboss-ejb3-embedded-standalone.jar. Make sure this jar is on your class path when you run your Embeddable EJB test.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Note that the jar has references to other jars via a Class-Path entry in the manifest. So if you copy it around make sure these are copied (or available) as well. The most important one being javassist.jar because of the way we've implement no-interface views.</p><h3><span>How to use in your code</span></h3><p>Now you can create any kind of session bean in your code and do a test on it using Embeddable.</p><pre class="jive-pre"><code class="jive-code">public class HelloBeanITCase
{
&#160;&#160; @Test
&#160;&#160; public void test1() throws NamingException
&#160;&#160; {
&#160;&#160;&#160;&#160;&#160; EJBContainer container = EJBContainer.createEJBContainer();

&#160;&#160;&#160;&#160;&#160; // Note that global naming isn't working yet.
&#160;&#160;&#160;&#160;&#160; InitialContext ctx = new InitialContext();
&#160;&#160;&#160;&#160;&#160; Hello bean = (Hello) ctx.lookup("HelloBean/local");

&#160;&#160;&#160;&#160;&#160; String now = new Date().toString();
&#160;&#160;&#160;&#160;&#160; String actual = bean.sayHello(now);

&#160;&#160;&#160;&#160;&#160; assertEquals("Hello " + now, actual);

&#160;&#160;&#160;&#160;&#160; container.close();
&#160;&#160; }
}</code></pre><p><br/>The test above is actually defined as an (Maven) integration test. This is because of the finacle details in class loading of the surefire plugin. So we'll use the failsafe plugin instead.</p><h3>How to run your test</h3><p>To run your test you need to have a full JBoss AS installation at hand. The standalone embeddable will delegate to <a class="jive-link-wiki-small" href="http://community.jboss.org/docs/DOC-13843">JBoss Embedded AS</a> to boot up an AS instance in your JVM.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li>Make sure either your environment variable JBOSS_HOME or system property jboss.home is setup properly.</li><li>Use the following command line '-Xmx512m -XX:MaxPermSize=256m -Djava.endorsed.dirs=$JBOSS_HOME/lib/endorsed'.</li></ol><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The pom.xml shown previously outlines how this can be achieved using the failsafe plugin. Surefire plugin does class loading trickery to get stuff up and running. This conflicts with the way Embedded works.</p><h3>Common Problems</h3><ol><li>OutOfMemoryError or empty Exception from main thread.<br/>Because we run the full AS within a JVM you need extra memory. There might even not be enough memory for a proper stack trace.<br/>Add '-Xmx512m -XX:MaxPermSize=256m' to your command line.</li><li>java.lang.NoSuchMethodError: javax.annotation.Resource.lookup()Ljava/lang/String;<br/>The current JDK comes with an older version of the Common Annotations API (JSR 250). The correct version is distributed with the AS installation. This is controlled with system property java.endorsed.dirs, which is not pointing to $JBOSS_HOME/lib/endorsed. (Note: Intellij has no environment variables replacing, best use full path.)<br/>Add '-Djava.endorsed.dirs=$JBOSS_HOME/lib/endorsed' to your command line.</li><li>Extremely slow startup and running of Embedded AS when using JDK logging.<br/>The JDK logging implementation is extremely slow, so jboss-ejb3-embeddable-standalone overrides this to use JBoss LogManager. This conflicts when you're using logging as well. The solution is to add jboss-logmanager to your class path (/project dependencies) and set '-Djava.util.logging.manager=org.jboss.logmanager.LogManager'. This also requires a proper logging configuration file.</li></ol><h3>Source</h3><p>The source for all code used in this article can be found on GitHub, <a class="jive-link-external-small" href="https://github.com/wolfc/jboss-beach-ejb3-embedded">https://github.com/wolfc/jboss-beach-ejb3-embedded</a>.</p><h3><span>Questions</span></h3><p>Please direct any questions to the <a class="jive-link-community-small" href="http://community.jboss.org/community/ejb3">EJB 3</a> space.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-9618">going to Community</a></p>

        <p style="margin: 0;">Create a new document in EJB3 at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>