2 Replies Latest reply on Jan 8, 2016 2:35 PM by matt_madhavan

    Wildfly 9.0.2 -  java.lang.ClassNotFoundException: javax.jms.ConnectionFactory

    matt_madhavan

      Hello,

      I have configure activemq ra successfully. When I start the server I see the following :

       

      12:46:30,154 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-2) WFLYJCA0002: Bound JCA AdminObject [java:/queue/HELLOWORLDMDBQueue]

      12:46:30,154 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-2) WFLYJCA0002: Bound JCA AdminObject [java:/topic/HELLOWORLDMDBTopic]

      12:46:30,154 INFO  [org.jboss.as.connector.deployment] (MSC service thread 1-2) WFLYJCA0002: Bound JCA ConnectionFactory

      [java:/activemq/xaConnectionFactory]

       

      When I deploy my war file I see the following error: I have been stuck on this for a while. Any ideas please?

       

      My activemq.rar configuration has reference to the javax.jms.

       

       

      Caused by: java.lang.ClassNotFoundException: javax.jms.ConnectionFactory from [Module "deployment.org.facs.ncdb.measuremesh.testutils-1.0-SNAPSHOT-2.war:main" from Service Module Loader]

          at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)

          at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)

          at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)



      Any ideas please? Thanks in advance!

       

      Thanks

      Matt'M

        • 1. Re: Wildfly 9.0.2 -  java.lang.ClassNotFoundException: javax.jms.ConnectionFactory
          jaysensharma

          Looks like your WAR: "testutils-1.0-SNAPSHOT-2.war"   is directly trying to access the "javax.jms" APIs hence you should add the following kind of "jboss-deployment-structure.xml" file inside your "testutils-1.0-SNAPSHOT-2.war/WEB-INF"  or you can also use the "testutils-1.0-SNAPSHOT-2.war/META-INF/MANIFEST.MF" based approach to add that dependency to your WAR.

           

          <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
              <deployment>
                  <dependencies>
                      <module name="javax.jms.api" />
                  </dependencies>
              </deployment>
          </jboss-deployment-structure>
          

           

          Alternatively if you have multiple applications and if you do not want to add above config inside your individual applications then you can also think about declaring Global Modules as an alternate approach:

           

          [standalone@localhost:9990 /] /subsystem=ee:write-attribute(name=global-modules,value=[{"name" => "javax.jms.api","slot" => "main"}])
          {"outcome" => "success"}
          [standalone@localhost:9990 /] :reload
          {
              "outcome" => "success",
              "result" => undefined
          }
          

           

           

          Generated XML snippet will be as following:

                  <subsystem xmlns="urn:jboss:domain:ee:3.0">
                      <global-modules>
                          <module name="javax.jms.api" slot="main"/>
                      </global-modules>
                     .
                     .
                     .
                  </subsystem>
          



          To know more about WildFly class loading please refer to:

          https://docs.jboss.org/author/display/WFLY9/Class+Loading+in+WildFly



          Regards

          Jay SenSharma

          • 2. Re: Wildfly 9.0.2 -  java.lang.ClassNotFoundException: javax.jms.ConnectionFactory
            matt_madhavan

            Hi Jay,

            I had to set the proxy inter face as follows (Line 5)

             

            @Bean(name = "amqXaConnectionFactory")
                public ConnectionFactory activeMQXAConnectionFactory() {
                    JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
                    jndiObjectFactoryBean.setJndiName(env.getProperty("jndi.name.jms.xaConnectionFactory"));
                    jndiObjectFactoryBean.setProxyInterface(ConnectionFactory.class); // org.apache.activemq.ra.ActiveMQConnectionFactory
            
                    try {
                        jndiObjectFactoryBean.afterPropertiesSet(); // HERE - This has to
                                                                    // called. Sane thing
                                                                    // with Drools/Spring
                                                                    // Config
                    } catch (IllegalArgumentException | NamingException e) {
                        e.printStackTrace();
                        LOG.error("Error looking up ActiveMQ Connection Factory", e);
                        throw new RuntimeException(e);
                    }
                    LOG.info("\n\n\n");
                    LOG.info("Connection Factory is : " + jndiObjectFactoryBean.getObject());
            
                    ConnectionFactory fac = (ConnectionFactory) jndiObjectFactoryBean.getObject();
            
                    try {
                        fac.createConnection();
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(0);
                    }
                    return (ConnectionFactory) jndiObjectFactoryBean.getObject();
                }
            

             

            And it worked ok :

            How ever line 20 throws the following excption and I am stumped, Any ideas please?

             

            org.springframework.aop.AopInvocationException: AOP configuration seems to be invalid: tried calling method [public abstract javax.jms.Connection javax.jms.ConnectionFactory.createConnection() throws javax.jms.JMSException] on target [org.apache.activemq.ra.ActiveMQConnectionFactory@281b4aa]; nested exception is java.lang.IllegalArgumentException: object is not an instance of declaring class
                at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:325)
                at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
                at com.sun.proxy.$Proxy107.createConnection(Unknown Source)
                at org.facs.ncdb.measuremesh.service.config.ResourcesConfig.activeMQXAConnectionFactory(ResourcesConfig.java:130)
                at org.facs.ncdb.measuremesh.service.config.ResourcesConfig$$EnhancerBySpringCGLIB$$6c4cf297.CGLIB$activeMQXAConnectionFactory$3(<generated>)
                at org.facs.ncdb.measuremesh.service.config.ResourcesConfig$$EnhancerBySpringCGLIB$$6c4cf297$$FastClassBySpringCGLIB$$cb0ad8e6.invoke(<generated>)
                at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
                at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
                 at org.facs.ncdb.measuremesh.service.config.ResourcesConfig$$EnhancerBySpringCGLIB$$6c4cf297.activeMQXAConnectionFactory(<generated>)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            

             

             

                @Bean(name = "amqXaConnectionFactory")
                public ConnectionFactory activeMQXAConnectionFactory() {
                    JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
                    jndiObjectFactoryBean.setJndiName(env.getProperty("jndi.name.jms.xaConnectionFactory"));
                    jndiObjectFactoryBean.setProxyInterface(ConnectionFactory.class); // org.apache.activemq.ra.ActiveMQConnectionFactory

             

                    try {
                        jndiObjectFactoryBean.afterPropertiesSet(); // HERE - This has to
                                                                    // called. Sane thing
                                                                    // with Drools/Spring
                                                                    // Config
                    } catch (IllegalArgumentException | NamingException e) {
                        e.printStackTrace();
                        LOG.error("Error looking up ActiveMQ Connection Factory", e);
                        throw new RuntimeException(e);
                    }
                    LOG.info("\n\n\n");
                    LOG.info("Connection Factory is : " + jndiObjectFactoryBean.getObject());

             

                    ConnectionFactory fac = (ConnectionFactory) jndiObjectFactoryBean.getObject();
                   
                    try {
                        fac.createConnection();
                    } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(0);
                    }
                    return (ConnectionFactory) jndiObjectFactoryBean.getObject();
                }