<!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;">
How to use an application client in JBoss-5
</h3>
<span style="margin-bottom: 10px;">
modified by <a href="http://community.jboss.org/people/WolfgangKnauf">Wolfgang Knauf</a> in <i>EJB3</i> - <a href="http://community.jboss.org/docs/DOC-12835">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>This wiki tries to explain the usage of application client container in JBoss. It consists of two parts: first an EJB is injected, the second part shows how to inject a MessageDrivenBean Queue.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h1>Injection of EJBs</h1><p>In this <span>example</span>, we are trying to inject an EJB into an application-client and then invoke a method on that EJB in the client. <em>This has been tested on JBoss-5 GA. The attached example is compiled with Java5.</em> So let's get started:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h6><strong>Step-1:Deploy th</strong><strong>e application</strong></h6><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Deploy the enterprise application which contains the EJB as well as the application-client, onto the JBoss-5 GA server. Here's what the Stateless.ear   contains:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier; font-size: 10pt;">META-INF/MANIFEST.MF<br/>StatelessEJB.jar<br/>StatelessClient.jar</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><br/>a) The StatelessEJB.jar is the jar which contains the EJB. The EJB is simple and has a couple of methods:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier; font-size: 10pt;">import javax.ejb.Stateless;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier; font-size: 10pt;">@Stateless<br/>public class GeometricModelBean<br/>  implements GeometricModelRemote, GeometricModelLocal<br/>{</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier; font-size: 10pt;"><br/>  public double computeCuboidVolume(double a, double b, double c)<br/>  {<br/>      // some code here<br/>  }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier; font-size: 10pt;">  public double computeCuboidSurface(double a, double b, double c)<br/>  {<br/>    // some code here<br/>  }<br/>}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>b) The StatelessClient.jar is the application client which uses the EJB (through injection). Here's the class which has the main function:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">import javax.ejb.EJB;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">public class GeometricModelApplicationClient<br/>{</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">  <strong>@EJB<br/>  public static GeometricModelRemote geometricModel;</strong></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">  public static void main(String[] args)<br/>  {<br/>    double dblVolume;<br/>    try<br/>    {<br/>      dblVolume = geometricModel.computeCuboidVolume(10.0D, 5.0D, 7.0D);<br/>      double dblSurface = geometricModel.computeCuboidSurface(10.0D, 5.0D, 7.0D);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">      System.out.println("Calculated volume: " + dblVolume + ", surface: " + dblSurface);<br/>    }<br/>    catch (Exception ex)<br/>    {<br/>      ex.printStackTrace();<br/>    }<br/>  }<br/>}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>As you can see, the EJB is being injected in the client and later on used to invoke a method. The  StatelessClient.jar should contain a application-client.xml and a jboss-client.xml (optional) to be identified as a application client. Here are the contents of these files:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><em>StatelessClient.jar /META-INF/application-client.xml</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;"><?xml version="1.0" encoding="UTF-8"?><br/><application-client id="Application-client_ID" version="5"<br/><span>    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><br/><span>    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><br/><span>    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://java.sun.com/xml/ns/javaee/application-client_5.xsd" target="_blank">http://java.sun.com/xml/ns/javaee/application-client_5.xsd</a><span>"></span><br/>    <br/>    <display-name>StatelessClient</display-name><br/>    <br/></application-client></span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><br/><em>StatelessClient.jar/META-INF/jboss-client.xml</em>:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;"><?xml version="1.0" encoding="UTF-8"?><br/><!DOCTYPE jboss-client PUBLIC<br/>    "-//JBoss//DTD Application Client 5.0//EN"<br/><span>    "</span><a class="jive-link-external-small" href="http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd" target="_blank">http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd</a><span>"></span><br/><jboss-client><br/>    <br/>    <jndi-name>StatelessClient</jndi-name><br/>    <br/></jboss-client> </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>And then the StatelessClient.jar/META-INF/MANIFEST.MF should point to the application client class which has the main function.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><em>StatelessClient.jar/META-INF/MANIFEST.MF</em>:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">Manifest-Version: 1.0<br/>Class-Path: StatelessEJB.jar<br/>Main-Class: de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Note that this ear does not have an application.xml. But if required, you can have one.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>When this EAR is successfully deployed on the JBoss-5 GA server, you will see the following log output on the console:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><br/><span style="font-family: courier new,courier;">13:55:57,734 INFO  [JBossASKernel] Created KernelDeployment for: StatelessClient.jar<br/>13:55:57,734 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=Stateless.ear,jar=StatelessClient.jar,name=StatelessClient,service=EJB3<br/>13:55:57,734 INFO  [JBossASKernel]   with dependencies:<br/>13:55:57,734 INFO  [JBossASKernel]   and demands:<br/>13:55:57,734 INFO  [JBossASKernel]   and supplies:<br/>13:55:57,734 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=Stateless.ear,jar=StatelessClient.jar,name=StatelessClient,service=EJB3) to KernelDeployment of: StatelessClient.jar<br/>13:56:00,156 INFO  [JBossASKernel] Created KernelDeployment for: StatelessEJB.jar<br/>13:56:00,156 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=Stateless_BrokenAppClient2.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3<br/>13:56:00,156 INFO  [JBossASKernel]   with dependencies:<br/>13:56:00,156 INFO  [JBossASKernel]   and demands:<br/>13:56:00,156 INFO  [JBossASKernel]      jboss.ejb:service=EJBTimerService<br/>13:56:00,156 INFO  [JBossASKernel]   and supplies:<br/>13:56:00,156 INFO  [JBossASKernel]      jndi:Stateless/GeometricModelBean/local-de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelLocal<br/>13:56:00,156 INFO  [JBossASKernel]      jndi:Stateless/GeometricModelBean/remote-de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote<br/>13:56:00,156 INFO  [JBossASKernel]      Class:de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote<br/>13:56:00,156 INFO  [JBossASKernel]      jndi:Stateless/GeometricModelBean/local<br/>13:56:00,156 INFO  [JBossASKernel]      Class:de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelLocal<br/>13:56:00,171 INFO  [JBossASKernel]      jndi:Stateless/GeometricModelBean/remote<br/>13:56:00,171 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=Stateless.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3) to KernelDeployment of: StatelessEJB.jar<br/>13:56:00,437 INFO  [ClientENCInjectionContainer] STARTED CLIENT ENC CONTAINER: StatelessClient<br/>13:56:01,171 INFO  [SessionSpecContainer] Starting jboss.j2ee:ear=Stateless_BrokenAppClient2.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3<br/>13:56:01,187 INFO  [EJBContainer] STARTED EJB: de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelBean ejbName: GeometricModelBean<br/>13:56:01,203 WARN  [SessionSpecContainer] Populating JBoss-specific annotation metadata manually until done by deployers: jboss.j2ee:ear=Stateless.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3<br/><br/>....<br/>13:56:01,656 INFO  [ServerImpl] JBoss (Microcontainer) [5.0.0.GA (build: SVNTag=JBoss_5_0_0_GA date=200809171046)] Started in 1m:8s:299ms</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>In your JNDIView you can now see that the application client has been bound to the JNDI:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">java:comp namespace of the component jboss.j2ee:ear=Stateless.ear,jar=StatelessEJB.jar,name=GeometricModelBean,service=EJB3 :</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">  +- EJBContext (class: javax.ejb.EJBContext)<br/>  +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)<br/>  +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)<br/>  +- env (class: org.jnp.interfaces.NamingContext)<br/>  +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">Global JNDI Namespace</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">  +- StatelessClient (class: org.jnp.interfaces.NamingContext)<br/>  |   +- UserTransaction[link -> UserTransaction] (class: javax.naming.LinkRef)<br/>  |   +- metaData (class: org.jboss.metadata.client.jboss.JBossClientMetaData)<br/>  |   +- env (class: org.jnp.interfaces.NamingContext)<br/>  |   |   +- geometricModel[link -> Stateless/GeometricModelBean/remote-de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelRemote] (class: javax.naming.LinkRef)<br/>  |   +- classPathEntries (class: java.util.ArrayList)</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h6><strong>Step-2: Use the </strong><strong>appclient-launcher to launch the application client container.</strong></h6><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Now that the EAR containing the bean and the application client has been deployed, the next step is to launch the application client container. Note: Just running the application client class through a java command will not get the injection working. You need the launcher to provide the application server functionalities.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>From the command prompt, 'cd' to %JBOSS_HOME%\client folder. I have JBoss installed in D:\jboss-5.0.0.GA so from my command prompt, i will cd to D:\jboss-5.0.0.GA\client folder:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">D:\jboss-5.0.0.GA\client>set JBOSS_HOME=d:\jboss-5.0.0.GA<br/>D:\jboss-5.0.0.GA\client>set JAVA_HOME=c:\jdk1.6.0_10<br/>D:\jboss-5.0.0.GA\client>set PATH=%JAVA_HOME%\bin;%PATH%</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Now use the following command to launch the application client container:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">D:\jboss-5.0.0.GA\client>%JAVA_HOME%\bin\java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://localhost:1099 -classpath "%JBOSS_HOME%\client\jbossall-client.jar;%JBOSS_HOME%\client\jboss-metadata.jar;%JBOSS_HOME%\lib\jboss-classloader.jar;%JBOSS_HOME%\lib\jboss-classloading-spi.jar;%JBOSS_HOME%\lib\jboss-classloading-vfs.jar;%JBOSS_HOME%\lib\jboss-classloading.jar;%JBOSS_HOME%\lib\jboss-dependency.jar;%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\lib\jboss-kernel.jar;%JBOSS_HOME%\lib\jboss-xml-binding.jar;%JBOSS_HOME%\lib\jboss-xml-binding.jar;%JBOSS_HOME%\lib\jboss-vfs.jar;%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\common\lib\jboss-ejb3-core.jar" org.jboss.client.AppClientMain -jbossclient de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient -launchers org.jboss.ejb3.client.ClientLauncher -j2ee.clientName StatelessClient</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><br/>The entire command should be in one single line. The important things to note in this command (other than the classpath stuff) is that:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>a) We are passing the JNDI related properties:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">-Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://localhost:1099</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The -Djava.naming.provider.url should point to the server's Naming port.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong><em>Where is the "<span style="font-family: courier new,courier;">-Djava.naming.factory.url.pkgs" argument?</span></em></strong></p><p>This argument is required, if the client app performs a JNDI lookup itself, and it's value has to be "<a class="jive-link-anchor-small">org.jboss.naming.client".</a></p><p>But this one is not used by the Injection framework. jaikirans investigations found that the environment property Context.URL_PKG_PREFIXES does not come into picture when using injection because of the way org.jboss.ejb3.client.JNDIDependencyItem is working. It does not look into the java:comp/env namespace but just looks up and adds a dependency on StatelessClient/metaData jndiname. Later on when the actual lookup for java:comp/env namespace is done on the jndi *server*, the properties that are on the server are used.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>b) We are calling the org.jboss.client.AppClientMain which is the application client container's entry point</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>c) We are passing -jbossclient parameter and its corresponding value de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient to org.jboss.client.AppClientMain. This is your application client main class which uses the EJB</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>d) We are also passing the -j2ee.clientName which is the name of your application client to org.jboss.client.AppClientMain. In this case, its StatelessClient.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>e) We are passing the -launchers org.jboss.ejb3.client.ClientLauncher to org.jboss.client.AppClientMain. This one is important. The -launchers accepts a comma separate list of fully qualified implementations of org.jboss.client.AppClientLauncher interface. The org.jboss.ejb3.client.ClientLauncher is one such implementation (provided by JBoss) which is responsible for injecting EJB (and some other things) in the application client.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>f) Classpath: the list of included JARs was found by "try and error" and might change with every JBoss version. The file list of this sample is for <strong>JBoss 5.0 GA</strong>.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>But <strong>JBoss 6.0GA</strong> requires a different file list. To simplify this, I use wildcards to include all JAR files in "%JBOSS_HOME%\client" and "%JBOSS_HOME\lib%". A new requirement in JBoss 6 is to include also "%JBOSS_HOME%\common\lib\jboss-ejb3-vfs-spi.jar".</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here is the relevant snippet of the command:</p><p><span style="font-family: courier new,courier;">set JBOSS_HOME=d:\jboss-6.0.0.Final</span></p><p><span style="font-family: courier new,courier;">...</span></p><p><span style="font-family: courier new,courier;">"%JAVA_HOME%\bin\java" ... -classpath .;"%JBOSS_HOME%\client\*;%JBOSS_HOME%\lib\*;%JBOSS_HOME%\common\lib\jboss-ejb3-vfs-spi.jar;" ...</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h6><strong>Step-3: See th</strong><strong>e output.</strong></h6><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>When you run the command mentioned in Step-2, the application client container will invoke the main method of your application client. In our example, the main method uses the injected EJB and invokes a method on the EJB and finally prints the following output on the client side:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">Calculated volume: 350.0, surface: 310.0</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Note, on the server side you might see the EJB related logs (if you have any logging messages).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>That's it!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>P.S: The application attached here is provided by Wolfgang Knauf</strong> <a class="jive-link-external-small" href="http://www.jboss.com/index.html?module=bb&op=viewtopic&t=143595">http://www.jboss.com/index.html?module=bb&op=viewtopic&t=143595</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>Why don't i see logs on the application client side?</h5><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>By default, with the command used in Step-2, you will not see the log message. The log messages are really useful when debugging any issue. You have to do 2 things to see logs on the client side:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>1) Add log4j.jar to the client classpath<br/>2) Add a log4j properties or xml file to the classpath or pass -Dlog4j.configuration=[path to log4j config file] JVM option.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>On my setup, i created a log4j.properties file with the following settings:</p><p><br/><span style="font-family: courier new,courier;">log4j.rootLogger=DEBUG, stdout</span></p><p><span style="font-family: courier new,courier;">log4j.appender.stdout=org.apache.log4j.ConsoleAppender<br/>log4j.appender.stdout.layout=org.apache.log4j.PatternLayout<br/>log4j.appender.stdout.layout.ConversionPattern=%d %p [%t][%c] - <%m>%n</span></p><p><br/>And then placed this file under %JBOSS_HOME%\client folder. Finally i changed the java command (in Step-2) to include the log4j.jar and also pass this log4j configuration file path as a JVM option. Here's the updated command:</p><p><br/><span style="font-family: courier new,courier;">D:\jboss-5.0.0.GA\client>%JAVA_HOME%\bin\java -Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.url=jnp://localhost:1099 -Dlog4j.configuration=%JBOSS_HOME%\client\log4j.properties -classpath "%JBOSS_HOME%\client\jbossall-client.jar;%JBOSS_HOME%\client\jboss-metadata.jar;%JBOSS_HOME%\client\log4j.jar;%JBOSS_HOME%\lib\jboss-classloader.jar;%JBOSS_HOME%\lib\jboss-classloading-spi.jar;%JBOSS_HOME%\lib\jboss-classloading-vfs.jar;%JBOSS_HOME%\lib\jboss-classloading.jar;%JBOSS_HOME%\lib\jboss-dependency.jar;%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\lib\jboss-kernel.jar;%JBOSS_HOME%\lib\jboss-xml-binding.jar;%JBOSS_HOME%\lib\jboss-vfs.jar;</span><span style="font-family: courier new,courier;">%JBOSS_HOME%\lib\jboss-reflect.jar;%JBOSS_HOME%\common\lib\jboss-ejb3-core.jar</span><span style="font-family: courier new,courier;">" org.jboss.client.AppClientMain -jbossclient de.fhw.komponentenarchitekturen.knauf.stateless.GeometricModelApplicationClient -launchers org.jboss.ejb3.client.ClientLauncher -j2ee.clientName StatelessClient</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>If Log4j does not show the expected results, add "<code>-Dlog4j.debug=true"</code> to the startup parameters, which will print Log4j debugging output and hopefully point you to the reason why e.g. the config file could not be found.</p><h5></h5><h1>Injection of a Queue</h1><p>(credits for this chapter go to jaikiran, I (Wolfgang) just documented his findings here, see <a class="jive-link-external-small" href="http://www.jboss.org/index.html?module=bb&op=viewtopic&t=149330">http://www.jboss.org/index.html?module=bb&op=viewtopic&t=149330</a> ).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Assume a client that wants to send data to a queue (e.g. a Message Driven Bean).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>You need a javax.jms.QueueConnectionFactory and a javax.jms.Queue, which will be injected by the container. As they are injected, they must be static variables in the class containing the "main" method (annotations will be added later):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">  private static QueueConnectionFactory queueConnectionFactory;</span></p><p><span style="font-family: courier new,courier;">  private static Queue queue;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>This is the code to send the message (one more "Hello World" sample ;-) ):</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span style="font-family: courier new,courier;">      QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();<br/>      QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);<br/>      QueueSender queueSender = queueSession.createSender(queue);</span></p><p><span style="font-family: courier new,courier;"><br/></span></p><p><span style="font-family: courier new,courier;">      //Send a text message:<br/>      TextMessage textMessage = queueSession.createTextMessage();<br/>      textMessage.setText("Hello World");</span></p><p><span style="font-family: courier new,courier;"><br/></span></p><p><span style="font-family: courier new,courier;">      queueSender.send(textMessage);</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>There are two possibilities to inject the Queue and QueueConnectionFactory.</p><p>We assume that our Queue (which points to a MDB) is bound to the global JNDI name "queue/MessageBeanQueue". The QueueConnectionFactory is provided by JBoss (you can find it in the JMXConsole as ObjectName "jboss.messaging.connectionfactory").</p><h5>1) From global JNDI</h5><p>This one is easy: the "mappedName" attribute of the <span style="font-family: courier new,courier;">@Resource</span> annotation points to the global JNDI names:</p><p><span style="font-family: courier new,courier;">  @Resource(mappedName="ConnectionFactory")<br/>  private static QueueConnectionFactory queueConnectionFactory;<br/>  <br/>  @Resource(mappedName="queue/MessageBeanQueue")  <br/>  private static Queue queue;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><h5>2) From Environment Naming Context (ENC)</h5><p>The "name" attribute of the <span style="font-family: courier new,courier;">@Resource</span> annotation points to ENC names:</p><p><span style="font-family: courier new,courier;">  @Resource(name="jms/MBConnectionFactory")<br/>  private static QueueConnectionFactory queueConnectionFactory;<br/>  <br/>  @Resource(name="jms/MBQueueRef")<br/>  private static Queue queue;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here you need two config files:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>application-client.xml</strong> looks like this:</p><p><span style="font-family: courier new,courier;"><?xml version="1.0" encoding="UTF-8"?><br/><application-client id="Application-client_ID" version="5"<br/><span>    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><br/><span>    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><br/><span>    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://java.sun.com/xml/ns/javaee/application-client_5.xsd" target="_blank">http://java.sun.com/xml/ns/javaee/application-client_5.xsd</a><span>"></span><br/>    ...<br/>   <resource-ref><br/>      <res-ref-name>jms/MBConnectionFactory</res-ref-name><br/>      <res-type>javax.jms.QueueConnectionFactory</res-type><br/>      <res-auth>Container</res-auth><br/>   </resource-ref><br/>   <br/>   <message-destination-ref><br/>      <message-destination-ref-name>jms/MBQueueRef</message-destination-ref-name><br/>      <message-destination-type>javax.jms.Queue</message-destination-type><br/>   </message-destination-ref></span><br/>   <br/></application-client></p><p>The <span style="font-family: courier new,courier;">QueueConnectionFactory</span> as declared as a <span style="font-family: courier new,courier;">resource-ref</span>, while the Queue is declared as a <span style="font-family: courier new,courier;">message-destination-ref</span> !</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><strong>jboss-client.xml</strong> handles the binding of the ENC entries to JBoss JNDI names:</p><p><span style="font-family: courier new,courier;"><?xml version="1.0" encoding="UTF-8"?><br/><!DOCTYPE jboss-client PUBLIC<br/>  "-//JBoss//DTD Application Client 5.0//EN"<br/><span>  "</span><a class="jive-link-external-small" href="http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd" target="_blank">http://www.jboss.org/j2ee/dtd/jboss-client_5_0.dtd</a><span>"></span><br/><jboss-client><br/>  <jndi-name>...</jndi-name><br/>  <resource-ref><br/>      <res-ref-name>jms/MBConnectionFactory</res-ref-name><br/>      <jndi-name>ConnectionFactory</jndi-name><br/>  </resource-ref><br/>  <br/>  <message-destination-ref><br/>      <message-destination-ref-name>jms/MBQueueRef</message-destination-ref-name><br/>      <jndi-name>queue/MessageBeanQueue</jndi-name><br/>  </message-destination-ref><br/></jboss-client></span></p><p>Same as in application-client.xml: The Queue must be declared as a <span style="font-family: courier new,courier;">message-destination-ref</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>A full sample can be found here: <a class="jive-link-external-small" href="http://www.informatik.fh-wiesbaden.de/~knauf/KomponentenArchitekturen2008/mdb/MessageInjection.ear">http://www.informatik.fh-wiesbaden.de/~knauf/KomponentenArchitekturen2008/mdb/MessageInjection.ear</a> (compiled with Java 1.6, will not run with 1.5)</p><p>It contains an EJB module with a MDB, and an application client module (simple swing client with a JTextField whose content is sent to the server). The queue is declared in the module with a -service.xml file in the EJB module. Simply deploy it to the server. To run the client: extract "MessageClient.jar" from the EAR to some other directory, and start the client using the ClientLauncher (see step 2 above).</p><p>The code is commented in German, but hopefully you will understand it anyway ;-)</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-12835">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>