title: Cannot instantiate class: org.apache.activemq.jndi.ActiveMQInitialContextFactory, using jmeter-maven-plugin
body: <p>In few words, if I run the JMeter plan test below from Maven it gives the outcome:</p>
  
  <pre><code>javax.naming.NamingException: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.activemq.jndi.ActiveMQInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.activemq.jndi.ActiveMQInitialContextFactory]
  </code></pre>
  
  <p>Nevertheless, if I run the same JMeter plan test without maven plugin, it runs correctly. </p>
  
  <p>Providing more details:</p>
  
  <p>If I start the ActiveMQ that way (Windows command prompty):</p>
  
  <pre><code>cd C:\_d\server\ActiveMQ\apache-activemq-5.9.0\bin
  activemq.bat
  </code></pre>
  
  <p>then, I run the the exact same jmx script that way:</p>
  
  <pre><code>jmeter.bat -n -t C:\_d\scripts\JMeter\JMS_SQS_MVN\SQS.jmx -l C:\temp\activemq.jtl -j C:\temp\activemq.jmx.log
  </code></pre>
  
  <p>I can go to ActiveMq console and see the queue created labeled sqs_dummy_mvn6 as it appears in such jmx script.</p>
  
  <p>Now, tring the same script but via maven plugin, it simply shows "Cannot instantiate class: org.apache.activemq.jndi.ActiveMQInitialContextFactory". Well, I understand that, whenever I use jmeter-maven-plugin, an embedded jmeter and an embedded activemq are started and stopped during the verify phase. </p>
  
  <p>I am calling the same script via maven that way:</p>
  
  <pre><code>mvn clean verify
  </code></pre>
  
  <p>...\artproducer\src\test\jmeter\SQS.jmx (below just the publisher is enabled; the subscribe is disabled to make the test a bit simpler)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jmeterTestPlan version="1.2" properties="2.9" jmeter="3.0 r1743807"&gt;
    &lt;hashTree&gt;
      &lt;TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Plano de Teste SQS" enabled="true"&gt;
        &lt;stringProp name="TestPlan.comments"&gt;&lt;/stringProp&gt;
        &lt;boolProp name="TestPlan.functional_mode"&gt;false&lt;/boolProp&gt;
        &lt;boolProp name="TestPlan.serialize_threadgroups"&gt;false&lt;/boolProp&gt;
        &lt;elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="Variáveis Definidas Pelo Usuário" enabled="true"&gt;
          &lt;collectionProp name="Arguments.arguments"/&gt;
        &lt;/elementProp&gt;
        &lt;stringProp name="TestPlan.user_define_classpath"&gt;&lt;/stringProp&gt;
      &lt;/TestPlan&gt;
      &lt;hashTree&gt;
        &lt;ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Grupo de Usuários - Consumers" enabled="true"&gt;
          &lt;stringProp name="ThreadGroup.on_sample_error"&gt;continue&lt;/stringProp&gt;
          &lt;elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Controlador de Iteração" enabled="true"&gt;
            &lt;boolProp name="LoopController.continue_forever"&gt;false&lt;/boolProp&gt;
            &lt;stringProp name="LoopController.loops"&gt;1&lt;/stringProp&gt;
          &lt;/elementProp&gt;
          &lt;stringProp name="ThreadGroup.num_threads"&gt;1&lt;/stringProp&gt;
          &lt;stringProp name="ThreadGroup.ramp_time"&gt;1&lt;/stringProp&gt;
          &lt;longProp name="ThreadGroup.start_time"&gt;1484067293000&lt;/longProp&gt;
          &lt;longProp name="ThreadGroup.end_time"&gt;1484067293000&lt;/longProp&gt;
          &lt;boolProp name="ThreadGroup.scheduler"&gt;false&lt;/boolProp&gt;
          &lt;stringProp name="ThreadGroup.duration"&gt;&lt;/stringProp&gt;
          &lt;stringProp name="ThreadGroup.delay"&gt;&lt;/stringProp&gt;
        &lt;/ThreadGroup&gt;
        &lt;hashTree&gt;
          &lt;SubscriberSampler guiclass="JMSSubscriberGui" testclass="SubscriberSampler" testname="JMS Subscriber" enabled="false"&gt;
            &lt;stringProp name="jms.jndi_properties"&gt;false&lt;/stringProp&gt;
            &lt;stringProp name="jms.initial_context_factory"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/stringProp&gt;
            &lt;stringProp name="jms.provider_url"&gt;tcp://localhost:61616&lt;/stringProp&gt;
            &lt;stringProp name="jms.connection_factory"&gt;ConnectionFactory&lt;/stringProp&gt;
            &lt;stringProp name="jms.topic"&gt;dynamicQueues/sqs_dummy_mvn6&lt;/stringProp&gt;
            &lt;stringProp name="jms.security_principle"&gt;&lt;/stringProp&gt;
            &lt;stringProp name="jms.security_credentials"&gt;&lt;/stringProp&gt;
            &lt;boolProp name="jms.authenticate"&gt;false&lt;/boolProp&gt;
            &lt;stringProp name="jms.iterations"&gt;1&lt;/stringProp&gt;
            &lt;stringProp name="jms.read_response"&gt;true&lt;/stringProp&gt;
            &lt;stringProp name="jms.client_choice"&gt;jms_subscriber_on_message&lt;/stringProp&gt;
            &lt;boolProp name="jms.stop_between_samples"&gt;true&lt;/boolProp&gt;
            &lt;stringProp name="jms.timeout"&gt;60000&lt;/stringProp&gt;
            &lt;boolProp name="jms.destination_static"&gt;false&lt;/boolProp&gt;
          &lt;/SubscriberSampler&gt;
          &lt;hashTree&gt;
            &lt;ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false"&gt;
              &lt;boolProp name="ResultCollector.error_logging"&gt;false&lt;/boolProp&gt;
              &lt;objProp&gt;
                &lt;name&gt;saveConfig&lt;/name&gt;
                &lt;value class="SampleSaveConfiguration"&gt;
                  &lt;time&gt;true&lt;/time&gt;
                  &lt;latency&gt;true&lt;/latency&gt;
                  &lt;timestamp&gt;true&lt;/timestamp&gt;
                  &lt;success&gt;true&lt;/success&gt;
                  &lt;label&gt;true&lt;/label&gt;
                  &lt;code&gt;true&lt;/code&gt;
                  &lt;message&gt;true&lt;/message&gt;
                  &lt;threadName&gt;true&lt;/threadName&gt;
                  &lt;dataType&gt;true&lt;/dataType&gt;
                  &lt;encoding&gt;false&lt;/encoding&gt;
                  &lt;assertions&gt;true&lt;/assertions&gt;
                  &lt;subresults&gt;true&lt;/subresults&gt;
                  &lt;responseData&gt;false&lt;/responseData&gt;
                  &lt;samplerData&gt;false&lt;/samplerData&gt;
                  &lt;xml&gt;false&lt;/xml&gt;
                  &lt;fieldNames&gt;true&lt;/fieldNames&gt;
                  &lt;responseHeaders&gt;false&lt;/responseHeaders&gt;
                  &lt;requestHeaders&gt;false&lt;/requestHeaders&gt;
                  &lt;responseDataOnError&gt;false&lt;/responseDataOnError&gt;
                  &lt;saveAssertionResultsFailureMessage&gt;true&lt;/saveAssertionResultsFailureMessage&gt;
                  &lt;assertionsResultsToSave&gt;0&lt;/assertionsResultsToSave&gt;
                  &lt;bytes&gt;true&lt;/bytes&gt;
                  &lt;threadCounts&gt;true&lt;/threadCounts&gt;
                  &lt;idleTime&gt;true&lt;/idleTime&gt;
                &lt;/value&gt;
              &lt;/objProp&gt;
              &lt;stringProp name="filename"&gt;&lt;/stringProp&gt;
            &lt;/ResultCollector&gt;
            &lt;hashTree/&gt;
          &lt;/hashTree&gt;
          &lt;ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="false"&gt;
            &lt;boolProp name="ResultCollector.error_logging"&gt;false&lt;/boolProp&gt;
            &lt;objProp&gt;
              &lt;name&gt;saveConfig&lt;/name&gt;
              &lt;value class="SampleSaveConfiguration"&gt;
                &lt;time&gt;true&lt;/time&gt;
                &lt;latency&gt;true&lt;/latency&gt;
                &lt;timestamp&gt;true&lt;/timestamp&gt;
                &lt;success&gt;true&lt;/success&gt;
                &lt;label&gt;true&lt;/label&gt;
                &lt;code&gt;true&lt;/code&gt;
                &lt;message&gt;true&lt;/message&gt;
                &lt;threadName&gt;true&lt;/threadName&gt;
                &lt;dataType&gt;true&lt;/dataType&gt;
                &lt;encoding&gt;false&lt;/encoding&gt;
                &lt;assertions&gt;true&lt;/assertions&gt;
                &lt;subresults&gt;true&lt;/subresults&gt;
                &lt;responseData&gt;false&lt;/responseData&gt;
                &lt;samplerData&gt;false&lt;/samplerData&gt;
                &lt;xml&gt;false&lt;/xml&gt;
                &lt;fieldNames&gt;true&lt;/fieldNames&gt;
                &lt;responseHeaders&gt;false&lt;/responseHeaders&gt;
                &lt;requestHeaders&gt;false&lt;/requestHeaders&gt;
                &lt;responseDataOnError&gt;false&lt;/responseDataOnError&gt;
                &lt;saveAssertionResultsFailureMessage&gt;true&lt;/saveAssertionResultsFailureMessage&gt;
                &lt;assertionsResultsToSave&gt;0&lt;/assertionsResultsToSave&gt;
                &lt;bytes&gt;true&lt;/bytes&gt;
                &lt;threadCounts&gt;true&lt;/threadCounts&gt;
                &lt;idleTime&gt;true&lt;/idleTime&gt;
              &lt;/value&gt;
            &lt;/objProp&gt;
            &lt;stringProp name="filename"&gt;&lt;/stringProp&gt;
          &lt;/ResultCollector&gt;
          &lt;hashTree/&gt;
          &lt;ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false"&gt;
            &lt;boolProp name="ResultCollector.error_logging"&gt;false&lt;/boolProp&gt;
            &lt;objProp&gt;
              &lt;name&gt;saveConfig&lt;/name&gt;
              &lt;value class="SampleSaveConfiguration"&gt;
                &lt;time&gt;true&lt;/time&gt;
                &lt;latency&gt;true&lt;/latency&gt;
                &lt;timestamp&gt;true&lt;/timestamp&gt;
                &lt;success&gt;true&lt;/success&gt;
                &lt;label&gt;true&lt;/label&gt;
                &lt;code&gt;true&lt;/code&gt;
                &lt;message&gt;true&lt;/message&gt;
                &lt;threadName&gt;true&lt;/threadName&gt;
                &lt;dataType&gt;true&lt;/dataType&gt;
                &lt;encoding&gt;false&lt;/encoding&gt;
                &lt;assertions&gt;true&lt;/assertions&gt;
                &lt;subresults&gt;true&lt;/subresults&gt;
                &lt;responseData&gt;false&lt;/responseData&gt;
                &lt;samplerData&gt;false&lt;/samplerData&gt;
                &lt;xml&gt;false&lt;/xml&gt;
                &lt;fieldNames&gt;true&lt;/fieldNames&gt;
                &lt;responseHeaders&gt;false&lt;/responseHeaders&gt;
                &lt;requestHeaders&gt;false&lt;/requestHeaders&gt;
                &lt;responseDataOnError&gt;false&lt;/responseDataOnError&gt;
                &lt;saveAssertionResultsFailureMessage&gt;true&lt;/saveAssertionResultsFailureMessage&gt;
                &lt;assertionsResultsToSave&gt;0&lt;/assertionsResultsToSave&gt;
                &lt;bytes&gt;true&lt;/bytes&gt;
                &lt;threadCounts&gt;true&lt;/threadCounts&gt;
                &lt;idleTime&gt;true&lt;/idleTime&gt;
              &lt;/value&gt;
            &lt;/objProp&gt;
            &lt;stringProp name="filename"&gt;&lt;/stringProp&gt;
          &lt;/ResultCollector&gt;
          &lt;hashTree/&gt;
          &lt;PublisherSampler guiclass="JMSPublisherGui" testclass="PublisherSampler" testname="JMS Publisher" enabled="true"&gt;
            &lt;stringProp name="jms.jndi_properties"&gt;false&lt;/stringProp&gt;
            &lt;stringProp name="jms.initial_context_factory"&gt;org.apache.activemq.jndi.ActiveMQInitialContextFactory&lt;/stringProp&gt;
            &lt;stringProp name="jms.provider_url"&gt;tcp://localhost:61616&lt;/stringProp&gt;
            &lt;stringProp name="jms.connection_factory"&gt;ConnectionFactory&lt;/stringProp&gt;
            &lt;stringProp name="jms.topic"&gt;dynamicQueues/sqs_dummy_mvn6&lt;/stringProp&gt;
            &lt;stringProp name="jms.expiration"&gt;&lt;/stringProp&gt;
            &lt;stringProp name="jms.priority"&gt;&lt;/stringProp&gt;
            &lt;stringProp name="jms.security_principle"&gt;&lt;/stringProp&gt;
            &lt;stringProp name="jms.security_credentials"&gt;&lt;/stringProp&gt;
            &lt;stringProp name="jms.text_message"&gt;testando a partir do JMeter4444&lt;/stringProp&gt;
            &lt;stringProp name="jms.input_file"&gt;&lt;/stringProp&gt;
            &lt;stringProp name="jms.random_path"&gt;&lt;/stringProp&gt;
            &lt;stringProp name="jms.config_choice"&gt;jms_use_text&lt;/stringProp&gt;
            &lt;stringProp name="jms.config_msg_type"&gt;jms_text_message&lt;/stringProp&gt;
            &lt;stringProp name="jms.iterations"&gt;1&lt;/stringProp&gt;
            &lt;boolProp name="jms.authenticate"&gt;false&lt;/boolProp&gt;
            &lt;elementProp name="jms.jmsProperties" elementType="JMSProperties"&gt;
              &lt;collectionProp name="JMSProperties.properties"/&gt;
            &lt;/elementProp&gt;
            &lt;boolProp name="jms.destination_static"&gt;false&lt;/boolProp&gt;
          &lt;/PublisherSampler&gt;
          &lt;hashTree&gt;
            &lt;ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false"&gt;
              &lt;boolProp name="ResultCollector.error_logging"&gt;false&lt;/boolProp&gt;
              &lt;objProp&gt;
                &lt;name&gt;saveConfig&lt;/name&gt;
                &lt;value class="SampleSaveConfiguration"&gt;
                  &lt;time&gt;true&lt;/time&gt;
                  &lt;latency&gt;true&lt;/latency&gt;
                  &lt;timestamp&gt;true&lt;/timestamp&gt;
                  &lt;success&gt;true&lt;/success&gt;
                  &lt;label&gt;true&lt;/label&gt;
                  &lt;code&gt;true&lt;/code&gt;
                  &lt;message&gt;true&lt;/message&gt;
                  &lt;threadName&gt;true&lt;/threadName&gt;
                  &lt;dataType&gt;true&lt;/dataType&gt;
                  &lt;encoding&gt;false&lt;/encoding&gt;
                  &lt;assertions&gt;true&lt;/assertions&gt;
                  &lt;subresults&gt;true&lt;/subresults&gt;
                  &lt;responseData&gt;false&lt;/responseData&gt;
                  &lt;samplerData&gt;false&lt;/samplerData&gt;
                  &lt;xml&gt;false&lt;/xml&gt;
                  &lt;fieldNames&gt;true&lt;/fieldNames&gt;
                  &lt;responseHeaders&gt;false&lt;/responseHeaders&gt;
                  &lt;requestHeaders&gt;false&lt;/requestHeaders&gt;
                  &lt;responseDataOnError&gt;false&lt;/responseDataOnError&gt;
                  &lt;saveAssertionResultsFailureMessage&gt;true&lt;/saveAssertionResultsFailureMessage&gt;
                  &lt;assertionsResultsToSave&gt;0&lt;/assertionsResultsToSave&gt;
                  &lt;bytes&gt;true&lt;/bytes&gt;
                  &lt;threadCounts&gt;true&lt;/threadCounts&gt;
                  &lt;idleTime&gt;true&lt;/idleTime&gt;
                &lt;/value&gt;
              &lt;/objProp&gt;
              &lt;stringProp name="filename"&gt;&lt;/stringProp&gt;
            &lt;/ResultCollector&gt;
            &lt;hashTree/&gt;
          &lt;/hashTree&gt;
        &lt;/hashTree&gt;
      &lt;/hashTree&gt;
    &lt;/hashTree&gt;
  &lt;/jmeterTestPlan&gt;
  </code></pre>
  
  <p>...\artproducer\target\jmeter\results\20170111-SQS.jtl</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;testResults version="1.2"&gt;
  &lt;sample t="0" it="0" lt="0" ts="0" s="false" lb="JMS Publisher" rc="000" rm="javax.naming.NamingException: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.activemq.jndi.ActiveMQInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.activemq.jndi.ActiveMQInitialContextFactory]" tn="Grupo de Usuários - Consumers 1-1" dt="" by="0" ng="1" na="1"/&gt;
  
  &lt;/testResults&gt;
  </code></pre>
  
  <p>pom:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;grpactivemq&lt;/groupId&gt;
      &lt;artifactId&gt;artproducer&lt;/artifactId&gt;
      &lt;!-- &lt;packaging&gt;pom&lt;/packaging&gt; --&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;artproducer Maven Webapp&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
      &lt;!-- enviando queue para o broker do ActiveMq iniciado como serviço --&gt;
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;jdk.version&gt;1.8&lt;/jdk.version&gt;
          &lt;junit.version&gt;4.11&lt;/junit.version&gt;
          &lt;activemq.version&gt;5.9.0&lt;/activemq.version&gt;
          &lt;spring.version&gt;4.1.5.RELEASE&lt;/spring.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;!-- activemq --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.activemq&lt;/groupId&gt;
              &lt;artifactId&gt;activemq-all&lt;/artifactId&gt;
              &lt;version&gt;${activemq.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Spring --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&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-jms&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- xbean --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.xbean&lt;/groupId&gt;
              &lt;artifactId&gt;xbean-spring&lt;/artifactId&gt;
              &lt;version&gt;3.7&lt;/version&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;${junit.version}&lt;/version&gt;
              &lt;!-- &lt;scope&gt;test&lt;/scope&gt; --&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
  
  &lt;!--            &lt;plugin&gt;
                  &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;Run load Test&lt;/id&gt;
                          &lt;phase&gt;generate-sources&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;exec&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;executable&gt;${basedir}/scripts/jmeter_exe.sh&lt;/executable&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt; --&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;com.lazerycode.jmeter&lt;/groupId&gt;
                  &lt;artifactId&gt;jmeter-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.0.3&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;jmeter-test&lt;/id&gt;
                          &lt;phase&gt;verify&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;jmeter&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
                  &lt;dependencies&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;org.apache.activemq&lt;/groupId&gt;
                          &lt;artifactId&gt;activemq-all&lt;/artifactId&gt;
                          &lt;version&gt;${activemq.version}&lt;/version&gt;
                      &lt;/dependency&gt;
                  &lt;/dependencies&gt;  
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${jdk.version}&lt;/source&gt;
                      &lt;target&gt;${jdk.version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
  
          &lt;finalName&gt;artproducer&lt;/finalName&gt;
  
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>