First, download and decompress cactus
The download address is http://java.chinaitlab.com/tools/45970.html. Copy the Cactus-ant-1.7.1.jar from the Cactus Lib directory to Ant's lib directory.
Second, configure Cactus
The cactus configuration is simple, create a new cactus.properties file, and place it under the classpath of the Cactus task in your ant script, which includes the following
cactus.sysproperties=cactus.contextURL
#cactus-sample-servlet-cactified就是你的测试应用所在路径,8080是端口号
cactus.contextURL = http://localhost:8080/cactus-sample-servlet-cactified
cactus.servletRedirectorName = ServletRedirector
cactus.jspRedirectorName = JspRedirector
cactus.filterRedirectorName = FilterRedirector
The concrete approach is further explained in conjunction with the ant script.
Third, run the ant script
The ant script mainly performs the following tasks
1, set Classpath
<path id="project.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<!-- cactus.properties文件就需要放在lib.dir所对应的路径中 -->
<pathelement location="${lib.dir}"/>
<pathelement location="${tomcat.home}/common/lib/jsp-api.jar"/>
<pathelement location="${tomcat.home}/common/lib/servlet-api.jar"/>
</path>
2. Define Related Tasks
<taskdef resource="cactus.tasks" classpathref="project.classpath"/>
<taskdef name="runservertests" classname="org.apache.cactus.integration.ant.
RunServerTestsTask">
<classpath>
<path refid="project.classpath"/>
</classpath>
</taskdef>
3, compile the application of the class file and test class file
4, packaging the entire application as a war file
It should be noted that not only do you want to package the application class, the test class will also be packaged
<target name="war" depends="compile.java"
description="Generate the runtime war">
<war warfile="${target.dir}/${project.name}.war"
webxml="${src.webapp.dir}/WEB-INF/web.xml">
<fileset dir="${src.webapp.dir}">
<exclude name="cactus-report.xsl"/>
<exclude name="WEB-INF/cactus-web.xml"/>
<exclude name="WEB-INF/web.xml"/>
</fileset>
<classes dir="${target.classes.java.dir}"/>
<!-- 别忘了打包测试类 -->
<classes dir="${target.classes.test.dir}"/>
<!-- 别忘了打包各种相关的jar文件 -->
< lib dir="project.classpath"/>
</war>
</target>