Home > Articles > Programming

  • Print
  • + Share This
Like this article? We recommend

The Ant Task

To be able to get Cactus to run the tests inside of an application server, the Cactus Ant task needs to be changed. Cactus needs to modify the war file for the application for it to execute. However, the application server needs an ear file to deploy the entity beans. Therefore some additional steps need to be added to the standard Cactus Ant task:

 <target name="test" depends="war">
  <cactifywar destfile="example.war" srcfile="dist/example.war"/>
  <ear destfile="example-cactus.ear" appxml="conf/application.xml">
  <fileset dir="." includes="example.war"/>
  <metainf dir="META-INF"/>
  <fileset dir="dist" includes="example.jar"/>
  <cactus haltonfailure="yes" showoutput="yes" printsummary="on"
  <cactusproperty server="false"
  <classpath refid="cactus.classpath"/>
   <jboss3x dir="${JBOSS3_HOME}" output="logs/jboss.cactus.log"
  <test name="com.dzrealms.example.entity.ExampleCactusTest"
   <formatter type="plain"/>

The first difference in this task is that the cactifywar is run and then an ear file is generated using that war file. This wraps Cactus' war file inside of an ear file for deployment into the application server.

The second difference is that the cactus tag itself is defining an ear file instead of a war file. This change of tags lets Cactus know that it is dealing with an enterprise application instead of a web application.

The third difference is that the container set is now pointing to JBoss instead of Tomcat. Inside of this tag, a config variable is set, which tells Cactus which server definition inside of JBoss it should start up and deploy to.

Once everything is configured correctly, calling 'ant test' will cause Cactus to build its war file, wrap it in an ear file, start up JBoss, and deploy the modified ear file. Once that is done, Cactus will then execute the tests defined against that instance. Any errors will be reported back to the user running the test.

  • + Share This
  • 🔖 Save To Your Account