Integrating Apache Ant with JMeter: Installation, Build.xml Configuration, and Test Execution
This guide explains how to install Apache Ant, configure a build.xml file to run JMeter tests and generate HTML reports, and execute the Ant build to produce performance test results, including troubleshooting common permission errors.
The tutorial demonstrates how to set up Apache Ant for automating JMeter performance tests. First, Ant is downloaded from the official site, unzipped, and environment variables ANT_HOME and PATH are configured; required JAR files are copied into Ant's lib directory.
Next, a build.xml file is created. It defines properties for JMeter home, result directories, and report naming, and includes three main targets:
run – calls the test and report targets.
test – loads the JMeter Ant task, points to the JMeter home, specifies the result JTL file, and runs all *.jmx scripts in the scripts folder.
report – uses XSLT to transform JTL files into summary and detailed HTML reports, and copies required image resources.
<?xml version="1.0" encoding="utf8"?>
<!-- Copy image resources needed for the report to the target directory -->
<project name="ant-jmeter-test" default="run" basedir=".">
<tstamp/>
<!-- Adjust to your local JMeter directory -->
<property name="jmeter.home" value="/usr/local/apache-jmeter-5.1.1"/>
<property name="jmeter.result.jtl.dir" value="./result/jtlfile"/>
<property name="jmeter.result.html.dir" value="./result/htmlfile"/>
<property name="ReportName" value="TestReport_"/>
<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl"/>
<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${time}_SummaryReport.html"/>
<property name="jmeter.detail.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl"/>
<property name="jmeter.detail.result.htmlName" value="${jmeter.result.html.dir}/${time}_DetailReport.html"/>
<target name="run">
<antcall target="test"/>
<antcall target="report"/>
</target>
<target name="test">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<testplans dir="./scripts" includes="*.jmx"/>
<property name="jmeter.save.saveservice.output_format" value="xml"/>
</jmeter>
</target>
<path id="xslt.classpath">
<fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
<fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
</path>
<target name="report">
<tstamp>
<format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/>
</tstamp>
<xslt classpathref="xslt.classpath" force="true" in="${jmeter.detail.result.jtlName}" out="${jmeter.detail.result.htmlName}" style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl">
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
<xslt classpathref="xslt.classpath" force="true" in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
<copy todir="${jmeter.result.html.dir}">
<fileset dir="${jmeter.home}/extras">
<include name="collapse.png"/>
<include name="expand.png"/>
</fileset>
</copy>
</target>
</project>To execute the build, run ant in the project directory. The output shows the JMeter test execution, a permission error for jmeter.log , and then the XSLT processing that generates the summary and detailed HTML reports, finally reporting a successful build.
The resulting reports are displayed as images (screenshots) illustrating the performance metrics and test details.
Thank you for reading; feel free to leave a comment or share this guide with others.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.