(1)解压ant、jmeter安装包,最好解压至同一个目录下

(2)配置jdk、ant

ant环境配置:

ANT_HOME:C:\apache-ant-1.9.13

CLASSPATH:C:\apache-ant-1.9.13\lib

Path:C:\apache-ant-1.9.13\bin

(3)解压ant_demo至jmeter目录下

(4)修改配置文件/jmeter/bin/jmeter.properties,去掉“#”,将jmeter.save.saveservice.output_format=csv修改为jmeter.save.saveservice.output_format=xml

 

(5)将/jmeter/extras/ant-jmeter-1.1.1文件拷贝至/ant/lib/下

 

 (6)修改apache-jmeter/ant_demo/build文件内容(build从其他地方拷贝过来)

 1 <?xml version="1.0" encoding="UTF8"?>
 2 
 3 <project name="Jmeter-TestCase" default="run" basedir=".">
 4 <tstamp>
 5 <format property="time" pattern="yyyyMMddhhmm" />
 6 </tstamp>
 7 
 8 <!--jmeter的目录-->
 9 <property name="jmeter.home" value="C:\apache-jmeter-4.0" />
10 <property name="jmeter.result.jtl.dir" value="C:\apache-jmeter-4.0\ant_demo\resultLog\jtl" />
11 <property name="jmeter.result.html.dir" value="C:\apache-jmeter-4.0\ant_demo\resultLog\html" />
12 
13 <property name="ReportName" value="TestReport" />
14 <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
15 <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
16 
17 <target name="run">
18 <antcall target="test" />
19 <antcall target="report" />
20 </target>
21 
22 <target name="test">
23 <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
24 <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
25 <testplans dir="C:\apache-jmeter-4.0\ant_demo\script" includes="Test.jmx" />
26 <property name="jmeter.save.saveservice.output_format" value="xml"/>
27 </jmeter>
28 </target>
29 
30 
31 
32 <target name="report">
33 <xslt in="${jmeter.result.jtlName}"
34 out="${jmeter.result.htmlName}"
35 style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" />
36 <copy todir="${jmeter.result.html.dir}">
37 <fileset dir="${jmeter.home}/extras">
38 <include name="collapse.png" />
39 <include name="expand.png" />
40 </fileset>
41 </copy>
42 </target>
43 
44 </project>
View Code

jmeter的安装目录及运行脚本后生成的结果目录

1      <!--jmeter的目录-->
2      <property name="jmeter.home" value="C:\apache-jmeter-4.0" />
3      <property name="jmeter.result.jtl.dir" value="C:\apache-jmeter-4.0\ant_demo\resultLog\jtl" />
4      <property name="jmeter.result.html.dir" value="C:\apache-jmeter-4.0\ant_demo\resultLog\html" />
View Code

jmeter运行脚本后生成的文件名称

1      <property name="ReportName" value="TestReport" />
2      <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
3      <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
View Code

jmeter所运行的脚本

1    <target name="test">
2          <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
3          <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
4             <testplans dir="C:\apache-jmeter-4.0\ant_demo\script" includes="Test.jmx" />
5              <property name="jmeter.save.saveservice.output_format" value="xml"/>
6          </jmeter>
7      </target>
View Code

(7)打开cmd,切换至jmeter/ant_demo目录下执行ant,至此搭建完成

 1 C:\apache-jmeter-4.0\ant_demo>ant
 2 Buildfile: C:\apache-jmeter-4.0\ant_demo\build.xml
 3 
 4 run:
 5 
 6 test:
 7    [jmeter] Executing test plan: C:\apache-jmeter-4.0\ant_demo\script\Test.jmx =
 8 => C:\apache-jmeter-4.0\ant_demo\resultLog\jtl\TestReport201808230105.jtl
 9    [jmeter] 八月 23, 2018 1:05:05 下午 java.util.prefs.WindowsPreferences <init>
10 
11    [jmeter] 警告: Could not open/create prefs root node Software\JavaSoft\Prefs
12 at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
13    [jmeter] Creating summariser <summary>
14    [jmeter] Created the tree successfully using C:\apache-jmeter-4.0\ant_demo\sc
15 ript\Test.jmx
16    [jmeter] Starting the test @ Thu Aug 23 13:05:06 CST 2018 (1535000706846)
17    [jmeter] Waiting for possible Shutdown/StopTestNow/Heapdump message on port 4
18 445
19    [jmeter] summary =     40 in 00:00:03 =   12.6/s Avg:   232 Min:   107 Max:
20  358 Err:     2 (5.00%)
21    [jmeter] Tidying up ...    @ Thu Aug 23 13:05:11 CST 2018 (1535000711613)
22    [jmeter] ... end of run
23 
24 report:
25      [xslt] Processing C:\apache-jmeter-4.0\ant_demo\resultLog\jtl\TestReport201
26 808230105.jtl to C:\apache-jmeter-4.0\ant_demo\resultLog\html\TestReport20180823
27 0105.html
28      [xslt] Loading stylesheet C:\apache-jmeter-4.0\extras\jmeter-results-detail
29 -report_21.xsl
30      [copy] Copying 2 files to C:\apache-jmeter-4.0\ant_demo\resultLog\html
31 
32 BUILD SUCCESSFUL
33 Total time: 9 seconds
View Code