3 Replies Latest reply on Jun 10, 2014 10:06 AM by raggz

    How to use JMS resources in Wildfly application client container?


      I'm trying to use Wildfly's application client container to run my JMS client but I'm not able to get work.


      I'm using the app client quick-start example that comes with wildfly quick-starts. I added a very simple class that inject a connection factory using @Resource. I have also modified the client container config (appclient.xml) so it does have jms components in it.


      @Resource(lookup = "java:/JmsXA")

        private ConnectionFactory cf;


      When I run my example I can see that the java:/jmsXA gets bounded as expected


      19:27:02,629 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-13) JBAS010401: Bound JCA ConnectionFactory [java:/JmsXA]


      In my code I do simple check to see if connections was injected.


      if ( cf != null){

           con = cf.createConnection();

      } else {


           LOG.log(Level.SEVERE,"Error: Connection Factory = null.");



      but all I see in the log file is always


      19:27:03,670 SEVERE [org.jboss.as.quickstarts.appclient.acc.client.JMSClient] (Thread-196) Error: Connection Factory = null.


      What am I doing wrong?

        • 1. Re: How to use JMS resources in Wildfly application client container?

          As per spec, only static fields of the main class are injected in a application client.

          • 2. Re: How to use JMS resources in Wildfly application client container?

            The related part of the JavaEE Platform Spec (JSR342) is here:


            EE.5.2.5 Annotations and Injection

            As described in the following sections, a field or method of certain container-

            managed component classes may be annotated to request that an entry from the

            application component’s environment be injected into the class. The specifications

            for the different containers indicate which classes are considered container-managed

            classes; not all classes of a given type are necessarily managed by the container.

            Any of the types of resources described in this chapter may be injected.

            Injection may also be requested using entries in the deployment descriptor

            corresponding to each of these resource types. The field or method may have any

            access qualifier ( public , private , etc.). For all classes except application client

            main classes, the fields or methods must not be static . Because application

            clients use the same lifecycle as Java SE applications, no instance of the

            application client main class is created by the application client container. Instead,

            the static main method is invoked. To support injection for the application client

            main class, the fields or methods annotated for injection must be static .

            A field of a class may be the target of injection. The field must not be final .

            By default, the name of the field is combined with the fully qualified name of the

            class and used directly as the name in the application component’s naming

            context. For example, a field named myDatabase in the class MyApp in the package

            com.example would correspond to the JNDI name java:comp/env/

            com.example.MyApp/myDatabase . The annotation also allows the JNDI name to be

            specified explicitly. When a deployment descriptor entry is used to specify

            injection, the JNDI name and the field name are both specified explicitly. Note

            that, by default, the JNDI name is relative to the java:comp/env naming context.


            Only the main-class static attributes are supported for injection, did not noticed that on top of my head.

            • 3. Re: How to use JMS resources in Wildfly application client container?

              Thanks for the answer. I must have missed that bit. It works now.