<!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;">
    Configuring Applications For Both Clustered And Non Clustered Environments
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/admin">Administrator Administrator</a> in <i>EJB3</i> - <a href="http://community.jboss.org/docs/DOC-13208">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>The aim of this wiki is to explain how to configure applications so that they can be deployed both as clustered and as non-clustered applications in the most efficient way.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h1>Do I Really Need To Do This?</h1><p>It's worth noting that often, one of the reasons to deploy a clustered application in a non-clustered environment is for development purpouses. Maintaining a network where different developers are creating their clusters can be quite tricky from a multicast traffic management perspective but there're workarounds available to disable multicast traffic from landing on the network. Tricks like <a class="jive-link-wiki-small" href="http://community.jboss.org/docs/DOC-10211">setting up clustering via localhost</a> or setting clustering traffic ttl to 0 via <span style="font-family: courier new,courier;">-Djgroups.udp.ip_ttl=0</span>, constrain multicast traffic to the local machine, hence allowing developers to run their own clusters locally without affecting others. If you feel you still need to configure your application for both clustered and non-clustered environments, please read ahead.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h1>EJB2 or EJB3 Deployments</h1><p>The easiest way to get EJBs deployed in as clustered in clustered environments and as non-clustered in non-clustered environments, is to define the clustering aspect via META-INF/jboss.xml rather than using @Clustered annotation in the case of EJB3s. JBoss has the capability of substituting pieces of XML with a specific value defined as a system property. So, for example, the following META-INF/jboss.xml allows you to control whether EJBs are deployed as clustered or not depending on whether <span style="font-family: courier new,courier;">-Dmyapp.is.clustered</span> is defined or not. If <span style="font-family: courier new,courier;">-Dmyapp.is.clustered=true</span> is passed when the server is started up, TimeTellerEjb will be deployed as clustered. If <span style="font-family: courier new,courier;">-Dmyapp.is.clustered=false</span> is passed or no system property is defined on startup, the EJB will be deployed as non-clustered:</p><pre class="jive-pre"><code class="jive-code jive-xml"><span class="jive-xml-tag">&lt;?xml version="1.0"?&gt;</span><br/>&lt;!DOCTYPE jboss PUBLIC <span class="jive-xml-quote">-//JBoss//DTD JBOSS 4.0//EN</span><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-quote"><a class="jive-link-external-small" href="http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd" target="_blank">http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd</a></span>&gt;<br/><span class="jive-xml-tag">&lt;jboss&gt;</span><br/>&#160; <span class="jive-xml-tag">&lt;enterprise-beans&gt;</span><br/>&#160;&#160;&#160; <span class="jive-xml-tag">&lt;session&gt;</span><br/>&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;ejb-name&gt;</span>TimeTellerEjb<span class="jive-xml-tag">&lt;/ejb-name&gt;</span><br/>&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;jndi-name&gt;</span>ejb/TimeTellerEjb<span class="jive-xml-tag">&lt;/jndi-name&gt;</span><br/>&#160;&#160;&#160;&#160;&#160; <span class="jive-xml-tag">&lt;clustered&gt;</span>${myapp.is.clustered:false}<span class="jive-xml-tag">&lt;/clustered&gt;</span><br/>&#160;&#160;&#160; <span class="jive-xml-tag">&lt;/session&gt;</span><br/>&#160; <span class="jive-xml-tag">&lt;/enterprise-beans&gt;</span><br/><span class="jive-xml-tag">&lt;/jboss&gt;</span></code></pre><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Unfortunately, there's currently no way of defining globally whether EJBs should be deployed as clustered or non-clustered.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h1>Web Deployments</h1><p>In the of case WAR deployments, the way a web application is marked as clustered is by setting &lt;distributable/&gt; XML configuration element in WEB-INF/web.xml. Unfortunately, &lt;distributable/&gt; is an empty element and hence the same trick used with EJBs cannot be used. However, there's no problem in deploying a web application marked as &lt;distributable/&gt; in a non-clustered environment. Worst case scenario you'll get a WARN message like this during deployment but the application will work fine:</p><pre class="jive-pre"><code class="jive-code">16:32:58,567 WARN&#160; [TomcatDeployer] Failed to setup clustering, clustering disabled. NoClassDefFoundError: org/jgroups/blocks/MethodCall</code></pre></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-13208">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>