gpt4 book ai didi

maven - 无法使用 jmeter-maven-plugin 实例化类 : org. apache.activemq.jndi.ActiveMQInitialContextFactory

转载 作者:行者123 更新时间:2023-12-02 20:52:48 24 4
gpt4 key购买 nike

简而言之,如果我从 Maven 运行下面的 JMeter 计划测试,它会给出结果:

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]

然而,如果我在没有 Maven 插件的情况下运行相同的 JMeter 计划测试,它会正确运行。

提供更多细节:

如果我以这种方式启动 ActiveMQ(Windows 命令提示符):

cd C:\_d\server\ActiveMQ\apache-activemq-5.9.0\bin
activemq.bat

然后,我以这种方式运行完全相同的 jmx 脚本:

jmeter.bat -n -t C:\_d\scripts\JMeter\JMS_SQS_MVN\SQS.jmx -l C:\temp\activemq.jtl -j C:\temp\activemq.jmx.log

我可以转到 ActiveMq 控制台并查看创建的标记为 sqs_dummy_mvn6 的队列,因为它出现在此类 jmx 脚本中。

现在,通过 maven 插件尝试相同的脚本,它只显示“无法实例化类:org.apache.activemq.jndi.ActiveMQInitialContextFactory”。好吧,我知道,每当我使用 jmeter-maven-plugin 时,嵌入式 jmeter 和嵌入式 activemq 都会在验证阶段启动和停止。

我以这种方式通过 maven 调用相同的脚本:

mvn clean verify

...\artproducer\src\test\jmeter\SQS.jmx(下面只是启用了发布者;禁用了订阅以使测试更简单一些)

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.9" jmeter="3.0 r1743807">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Plano de Teste SQS" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="Variáveis Definidas Pelo Usuário" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Grupo de Usuários - Consumers" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Controlador de Iteração" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">1</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<longProp name="ThreadGroup.start_time">1484067293000</longProp>
<longProp name="ThreadGroup.end_time">1484067293000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
<hashTree>
<SubscriberSampler guiclass="JMSSubscriberGui" testclass="SubscriberSampler" testname="JMS Subscriber" enabled="false">
<stringProp name="jms.jndi_properties">false</stringProp>
<stringProp name="jms.initial_context_factory">org.apache.activemq.jndi.ActiveMQInitialContextFactory</stringProp>
<stringProp name="jms.provider_url">tcp://localhost:61616</stringProp>
<stringProp name="jms.connection_factory">ConnectionFactory</stringProp>
<stringProp name="jms.topic">dynamicQueues/sqs_dummy_mvn6</stringProp>
<stringProp name="jms.security_principle"></stringProp>
<stringProp name="jms.security_credentials"></stringProp>
<boolProp name="jms.authenticate">false</boolProp>
<stringProp name="jms.iterations">1</stringProp>
<stringProp name="jms.read_response">true</stringProp>
<stringProp name="jms.client_choice">jms_subscriber_on_message</stringProp>
<boolProp name="jms.stop_between_samples">true</boolProp>
<stringProp name="jms.timeout">60000</stringProp>
<boolProp name="jms.destination_static">false</boolProp>
</SubscriberSampler>
<hashTree>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
<ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="false">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<PublisherSampler guiclass="JMSPublisherGui" testclass="PublisherSampler" testname="JMS Publisher" enabled="true">
<stringProp name="jms.jndi_properties">false</stringProp>
<stringProp name="jms.initial_context_factory">org.apache.activemq.jndi.ActiveMQInitialContextFactory</stringProp>
<stringProp name="jms.provider_url">tcp://localhost:61616</stringProp>
<stringProp name="jms.connection_factory">ConnectionFactory</stringProp>
<stringProp name="jms.topic">dynamicQueues/sqs_dummy_mvn6</stringProp>
<stringProp name="jms.expiration"></stringProp>
<stringProp name="jms.priority"></stringProp>
<stringProp name="jms.security_principle"></stringProp>
<stringProp name="jms.security_credentials"></stringProp>
<stringProp name="jms.text_message">testando a partir do JMeter4444</stringProp>
<stringProp name="jms.input_file"></stringProp>
<stringProp name="jms.random_path"></stringProp>
<stringProp name="jms.config_choice">jms_use_text</stringProp>
<stringProp name="jms.config_msg_type">jms_text_message</stringProp>
<stringProp name="jms.iterations">1</stringProp>
<boolProp name="jms.authenticate">false</boolProp>
<elementProp name="jms.jmsProperties" elementType="JMSProperties">
<collectionProp name="JMSProperties.properties"/>
</elementProp>
<boolProp name="jms.destination_static">false</boolProp>
</PublisherSampler>
<hashTree>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</hashTree>
</hashTree>
</jmeterTestPlan>

...\artproducer\target\jmeter\results\20170111-SQS.jtl

<?xml version="1.0" encoding="UTF-8"?>
<testResults version="1.2">
<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"/>

</testResults>

任务:

<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">
<modelVersion>4.0.0</modelVersion>
<groupId>grpactivemq</groupId>
<artifactId>artproducer</artifactId>
<!-- <packaging>pom</packaging> -->
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>artproducer Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- enviando queue para o broker do ActiveMq iniciado como serviço -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jdk.version>1.8</jdk.version>
<junit.version>4.11</junit.version>
<activemq.version>5.9.0</activemq.version>
<spring.version>4.1.5.RELEASE</spring.version>
</properties>

<dependencies>
<!-- activemq -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>${activemq.version}</version>
</dependency>

<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- xbean -->
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>3.7</version>
</dependency>

<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<!-- <scope>test</scope> -->
</dependency>
</dependencies>

<build>
<plugins>

<!-- <plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Run load Test</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/scripts/jmeter_exe.sh</executable>
</configuration>
</execution>
</executions>
</plugin> -->

<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-test</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>${activemq.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>

<finalName>artproducer</finalName>

</build>
</project>

最佳答案

我认为您需要添加 activemq-all.jar依赖于 /lib/ext JMeter 的文件夹,如所述here ,语法与 <dependency> 略有不同你用过:

        <plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.0.3</version>
<executions>
<execution>
<id>jmeter-test</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<jmeterExtensions>
<artifact>org.apache.activemq:activemq-all:jar:${activemq.version}</artifact>
</jmeterExtensions>
</configuration>
</plugin>

关于maven - 无法使用 jmeter-maven-plugin 实例化类 : org. apache.activemq.jndi.ActiveMQInitialContextFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41600180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com