title: ClassNotFoundException: com.ibm.mq.jms.MQConnectionFactory (Websphere MQ 7.5 + spring jms + maven tomcat 7 plugin)
body: <p><strong>I am trying to create simple Webapp to demonstrate the using WMQ 7.5 in Servlet Container (tomcat). My webbap is based on standalone WMQ sample app.
  My standalone app works good.</strong></p>
  
  <p><strong>The testcase is also good.</strong> </p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = AppConfig.class)
  public class MQMessageTest {
  
      /**
       * Message count fot test
       */
      private static final int MESSAGE_COUNT = 25;
  
      /**
       * Setting Environment for getting properties
       */
      @Autowired
      private Environment environment;
  
      /**
       * MQMessageSender for sending messages
       */
      @Autowired
      private MQMessageSender mqMessageSender;
  
      /**
       * JmsTemplate of Spring JMS
       */
      @Autowired
      private JmsTemplate jmsTemplate;
  
      @Test
      public void testEqualsOfSentAndReceivedMessages() {
  
          /*Sending messages to Queue*/
          for (int i = 0; i &lt; MESSAGE_COUNT; i++) {
              mqMessageSender.send("Message with" + System.nanoTime());
          }
  
          /*Container for received messages*/
          Set&lt;TextMessage&gt; messages = new HashSet&lt;TextMessage&gt;();
  
          /*Receiving messages from report Queue*/
          for (int i = 0; i &lt; MESSAGE_COUNT; i++) {
              TextMessage message = (TextMessage) jmsTemplate.receive(environment.getRequiredProperty("wmq.queue.test.input.2"));
              messages.add(message);
          }
  
          assertEquals(messages.size(), MESSAGE_COUNT);
      }
  }
  </code></pre>
  
  <p><strong>But when I am starting tomcat I have the following issue:</strong></p>
  
  <pre><code>org.springframework.web.context.support.AnnotationConfigWebApplicationContext loadBeanDefinitions
  INFO: Registering annotated classes: [class by.iba.config.AppConfig]
  июн 08, 2015 9:29:11 AM org.apache.catalina.core.ApplicationContext log
  SEVERE: StandardWrapper.Throwable
  **java.lang.NoClassDefFoundError: com/ibm/mq/jms/MQConnectionFactory**
      at java.lang.Class.getDeclaredMethods0(Native Method)
      at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
      at java.lang.Class.getDeclaredMethods(Class.java:1860)
      at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:140)
  
  ... 30 more
  
  июн 08, 2015 9:29:11 AM org.apache.catalina.core.StandardContext loadOnStartup
  **SEVERE: Servlet /mqservice-webapp threw load() exception
  java.lang.ClassNotFoundException: com.ibm.mq.jms.MQConnectionFactory**
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
  
  ......
  </code></pre>
  
  <p><strong>Please tell me what's the problem. How can I resolve it? Whe it need to be fixed: in tomcat or websphere MQ or spring jms? I was trying to work with jetty but it was fail.</strong> </p>
  
  <p>My POM</p>
  
  <pre><code>&lt;project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;by.iba&lt;/groupId&gt;
      &lt;artifactId&gt;mqservice-webapp&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;Web MQ Module&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;websphereMq.version&gt;7.5.0.2&lt;/websphereMq.version&gt;
          &lt;wmq.jars&gt;${basedir}/lib&lt;/wmq.jars&gt;
          &lt;spring.version&gt;4.0.6.RELEASE&lt;/spring.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;!--Websphere MQ dependencies--&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm&lt;/groupId&gt;
              &lt;artifactId&gt;com.ibm.mqjms&lt;/artifactId&gt;
              &lt;version&gt;${websphereMq.version}&lt;/version&gt;
              &lt;scope&gt;system&lt;/scope&gt;
              &lt;systemPath&gt;${wmq.jars}/com.ibm.mqjms.jar&lt;/systemPath&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm&lt;/groupId&gt;
              &lt;artifactId&gt;com.ibm.mq.headers&lt;/artifactId&gt;
              &lt;version&gt;${websphereMq.version}&lt;/version&gt;
              &lt;scope&gt;system&lt;/scope&gt;
              &lt;systemPath&gt;${wmq.jars}/com.ibm.mq.headers.jar&lt;/systemPath&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm&lt;/groupId&gt;
              &lt;artifactId&gt;com.ibm.mq.jmqi&lt;/artifactId&gt;
              &lt;version&gt;${websphereMq.version}&lt;/version&gt;
              &lt;scope&gt;system&lt;/scope&gt;
              &lt;systemPath&gt;${wmq.jars}/com.ibm.mq.jmqi.jar&lt;/systemPath&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.ibm&lt;/groupId&gt;
              &lt;artifactId&gt;com.ibm.dhbcore&lt;/artifactId&gt;
              &lt;version&gt;${websphereMq.version}&lt;/version&gt;
              &lt;scope&gt;system&lt;/scope&gt;
              &lt;systemPath&gt;${wmq.jars}/dhbcore.jar&lt;/systemPath&gt;
          &lt;/dependency&gt;
  
          &lt;!--Spring--&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-jms&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.geronimo.specs&lt;/groupId&gt;
              &lt;artifactId&gt;geronimo-jms_1.1_spec&lt;/artifactId&gt;
              &lt;version&gt;1.1.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!--Javax Servlet API--&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!--Junit--&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.6&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
  
              &lt;!-- Jetty Plugin --&gt;
  
              &lt;!--&lt;plugin&gt;--&gt;
                  &lt;!--&lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;--&gt;
                  &lt;!--&lt;artifactId&gt;maven-jetty-plugin&lt;/artifactId&gt;--&gt;
                  &lt;!--&lt;version&gt;6.1.10&lt;/version&gt;--&gt;
              &lt;!--&lt;/plugin&gt;--&gt;
  
              &lt;!-- Set JDK Compiler Level --&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.3&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                      &lt;encoding&gt;${project.build.sourceEncoding}&lt;/encoding&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;!-- Tomcat Plugin --&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
                  &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.2&lt;/version&gt;
                  &lt;configuration&gt;
                     &lt;server&gt;local_tomcat&lt;/server&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.4&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;warName&gt;mqservice-webapp&lt;/warName&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>WebConfig</strong></p>
  
  <pre><code>@Configuration
  @ComponentScan({"..."})
  @PropertySource(value = {"classpath:by.iba/wmq.properties"})
  public class AppConfig {
  
      /**
       * Logger is using for tracing status of the application configuration
       */
      public static final Logger LOGGER = Logger.getLogger(AppConfig.class.getName());
  
      /**
       * Environment Bean for working with properties
       */
      @Autowired
      private Environment environment;
  
      /**
       * Method provides setting up the MQConnectionFactory Bean in Binding mode
       *
       * @return MQConnectionFactory is set up in binding mode
       * @throws JMSException if setting up MQConnectionFactory failed
       */
      @Bean
      public MQConnectionFactory mqBindingConnectionFactory() {
          MQConnectionFactory connectionFactory = new MQConnectionFactory();
          try {
              connectionFactory.setHostName(environment.getRequiredProperty("wmq.qmgr.host"));
              connectionFactory.setPort(environment.getProperty("wmq.qmgr.port", Integer.class));
              connectionFactory.setQueueManager(environment.getRequiredProperty("wmq.qmgr.name"));
              connectionFactory.setTransportType(environment.getProperty("wmq.qmgr.transport.type.binding", Integer.class));
              connectionFactory.setCCSID(environment.getProperty("wmq.qmgr.ccsid", Integer.class));
          } catch (JMSException e) {
              LOGGER.severe("Cannot set up binding connection factory" + e.getMessage());
          }
          return connectionFactory;
      }
  
      /**
       * Method provides setting up the MQConnectionFactory Bean in Client mode
       *
       * @return MQConnectionFactory is set up in client mode
       * @throws JMSException if setting up MQConnectionFactory failed
       */
      @Bean
      public MQConnectionFactory mqClientConnectionFactory() {
          MQConnectionFactory connectionFactory = new MQConnectionFactory();
          try {
              connectionFactory.setHostName(environment.getRequiredProperty("wmq.qmgr.host"));
              connectionFactory.setPort(environment.getProperty("wmq.qmgr.port", Integer.class));
              connectionFactory.setQueueManager(environment.getRequiredProperty("wmq.qmgr.name"));
              connectionFactory.setTransportType(environment.getProperty("wmq.qmgr.transport.type.client", Integer.class));
              connectionFactory.setCCSID(environment.getProperty("wmq.qmgr.ccsid", Integer.class));
              connectionFactory.setChannel(environment.getRequiredProperty("wmq.qmgr.channel"));
          } catch (JMSException je) {
              LOGGER.severe("Cannot set up client connection factory" + je.getMessage());
          }
          return connectionFactory;
      }
  
      /**
       * Method provides setting up Single Connection Factory Bean for using in Binding mode
       *
       * @return SingleConnectionFactory
       */
      @Bean
      public SingleConnectionFactory jmsQueueConnectionFactory() {
          SingleConnectionFactory singleConnectionFactory = new SingleConnectionFactory();
          singleConnectionFactory.setTargetConnectionFactory(mqBindingConnectionFactory());
          singleConnectionFactory.setReconnectOnException(true);
          return singleConnectionFactory;
      }
  
      /**
       * Method provides setting up UserCredentialsConnectionFactoryAdapter Bean for using in Client mode
       *
       * @return UserCredentialsConnectionFactoryAdapter
       */
      @Bean
      public UserCredentialsConnectionFactoryAdapter jmsQueueConnectionFactorySecured() {
          UserCredentialsConnectionFactoryAdapter connectionFactoryAdapter = new UserCredentialsConnectionFactoryAdapter();
          connectionFactoryAdapter.setTargetConnectionFactory(mqClientConnectionFactory());
          connectionFactoryAdapter.setUsername(environment.getRequiredProperty("wmq.qmgr.username"));
          connectionFactoryAdapter.setPassword(environment.getRequiredProperty("wmq.qmgr.password"));
          return connectionFactoryAdapter;
      }
  
      /**
       * Method provides setting up CachingConnectionFactory Bean to organize connection pool
       *
       * @return CachingConnectionFactory
       */
      @Bean
      public CachingConnectionFactory cachingConnectionFactory() {
          CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
          cachingConnectionFactory.setTargetConnectionFactory(jmsQueueConnectionFactorySecured());
          cachingConnectionFactory.setCacheConsumers(true);
          cachingConnectionFactory.setCacheProducers(true);
          cachingConnectionFactory.setSessionCacheSize(5);
          return cachingConnectionFactory;
      }
  
      /**
       * Method provides setting up DynamicDestinationResolver Bean
       *
       * @return DynamicDestinationResolver
       */
      @Bean
      public DynamicDestinationResolver destinationResolver() {
          return new DynamicDestinationResolver();
      }
  
      /**
       * Method provides setting up JmsTemplate Bean
       *
       * @return DynamicDestinationResolver
       */
      @Bean
      public JmsTemplate jmsQueueTemplate() {
          JmsTemplate jmsTemplate = new JmsTemplate();
          jmsTemplate.setConnectionFactory(jmsQueueConnectionFactorySecured()); // optionally switching client mode
  //        jmsTemplate.setConnectionFactory(jmsQueueConnectionFactory()); // optionally switching binding mode
          jmsTemplate.setDestinationResolver(destinationResolver());
          jmsTemplate.setReceiveTimeout(10000);
          return jmsTemplate;
      }
  
      /**
       * Method provides setting up MQMessageListener Bean for getting messages
       * from Websphere MQ and his personal settings
       *
       * @return MQMessageListener
       */
      @Bean
      public MQMessageListener mqMessageListener() {
          return new MQMessageListener();
      }
  
      /**
       * Method provides MQMessageSender Bean for sending messages
       * to Websphere MQ and his personal settings
       *
       * @return @MQMessageSender
       */
      @Bean
      public MQMessageSender mqMessageSender() {
          MQMessageSender mqMessageSender = new MQMessageSender();
          mqMessageSender.setDestinationQueue(environment.getRequiredProperty("wmq.queue.test.input.1"));
          mqMessageSender.setForwardQueue(environment.getRequiredProperty("wmq.queue.test.input.2"));
          return mqMessageSender;
      }
  
      /**
       * Method provides DefaultMessageListenerContainer Bean for sending messages
       *
       * @return DefaultMessageListenerContainer
       */
      @Bean
      public DefaultMessageListenerContainer jmsListenerContainer() {
          DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
          try {
              dmlc.setConnectionFactory(mqClientConnectionFactory()); // optionally switching client mode
  //            dmlc.setConnectionFactory(mqBindingConnectionFactory()); // optionally switching binding mode
              dmlc.setConcurrentConsumers(environment.getProperty("wmq.listener.concurrent.consumers", Integer.class));
              dmlc.setMessageListener(mqMessageListener());
              dmlc.setDestination(new MQDestination(environment.getRequiredProperty("wmq.queue.test.input.1")));
          } catch (JMSException je) {
              LOGGER.severe(je.getMessage());
          }
          return dmlc;
      }
  
  }
  </code></pre>
  
  <p>WEB Initializer</p>
  
  <pre><code>public class WebInitializer implements WebApplicationInitializer {
  
      @Override
      public void onStartup(ServletContext servletContext) throws ServletException {
          AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
          ctx.register(AppConfig.class);
          ctx.setServletContext(servletContext);
  
          ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
          servlet.setLoadOnStartup(1);
          servlet.addMapping("/");
      }
  }
  </code></pre>
  
  <p>Thanks a lot. Sorry for my English</p>