ILOG JRules User Guide > Testing Rules with Rule Scenario Manager > Tasks > Executing Scenarios, Scenario Suites, Simulations, and RSM Archives > Ant Commands for Scenario Execution

If you want to run your scenario, scenario suite, or simulation in a command line, you have to write the corresponding JUnit tests (http://junit.sourceforge.net) and run it with a JUnit runner (textUI, SwingUI ...). This is done with the suite() method, which creates a suite containing all your test methods:

package mypackage;
 
// jrules-rsm-core.jar
import ilog.rules.ras.binding.xml.impl.IlrXMLRSMBindingObjectImpl;
import ilog.rules.ras.core.scenario.impl.IlrScenarioSuiteImpl;
import ilog.rules.ras.core.scenario.impl.wrapper.IlrScenarioSuiteWrapperImpl;
 
// junit.jar
import junit.framework.Test;
 
public class MyScenarioJUnit {
 
  public static Test suite() throws Exception {
 
    // Use the RSM Binding class to read the set of files
    IlrXMLRSMBindingObjectImpl binding = new IlrXMLRSMBindingObjectImpl();
    binding.setBindingComplement("pathTo/ScenarioFile.xml");
    
    // Initialize the element with the correct wrapper
    IlrScenarioImpl element = new
      IlrScenarioImpl((IlrScenarioWrapperImpl)binding.fromBinding());
 
    // Return the element that extends the JUnit TestSuite class
    return element;
  }
}

Then, write the correct Ant task to run the JUnit class written previously, by either:

In either case, you have to specify the Java library and configuration files to use in the classpath property:

<path id="jrules.classpath">
  <fileset dir="${jrules.lib.dir}">
    <include name="jrules-bres-execution.jar" />
    <include name="jrules-engine.jar" />
    <include name="jrules-bres-manage-tools.jar" />
    <include name="jrules-binding.jar" />
    <include name="jrules-shared.jar" />
    <include name="jrules-om.jar" />
    <include name="commons-beanutils.jar" />
    <include name="commons-collections.jar" />
    <include name="commons-logging.jar"/>
    <include name="j2ee_connector-1_0-fr.jar"/>
    <include name="jax-qname.jar"/>
    <include name="jstl.jar"/>
    <include name="sam.jar"/>
    <include name="log4j.jar"/> 
    <include name="jaxrpc-api.jar" />		
    <include name="axis.jar" />
    <include name="wsdl4j.jar" />
    <include name="saaj-api.jar" />
    <include name="commons-discovery.jar" />
    <include name="bcel.jar" />
    <include name="sax.jar" />
    <include name="dom.jar" />
    <include name="xercesImpl.jar" />			
    <include name="jaxp-api.jar" />
    <include name="logging.jar" />
    <include name="commons-digester.jar" />
  </fileset>
  <fileset dir="${rsm.lib.dir}">
    <include name="commons-lang-2.1.jar" />	
    <include name="jrules-rsm-common.jar" />
    <include name="jrules-rsm-core.jar" />
    <!-- JUnit --><include name="junit-3.8.1.jar"/>
    <!-- JDO Binding --><include name="hsqldb.jar" />
    <!-- JDO Binding --><include name="jdo2-api-2.0-rc1.jar" />
    <!-- JDO Binding --><include name="jpox-1.1.0-rc-1.jar" />
    <!-- XStream Serrialization / Deserialization --> 
    <include name="joda-time-1.0.jar"/>
    <include name="xpp3-1.1.3.4d_b4_min.jar"/>
    <include name="xstream-1.1.2.jar"/>
    <include name="xmlutil.jar"/>
    <!-- JXL --><include name="jxl.jar"/>
    <!-- JXL --><include name="commons-codec-1.3.jar"/>
  </fileset>
</path>

An example of an Ant execution is the following:

<!-- =================================================================== -->
<!-- Run in text mode                                                    -->
<!-- =================================================================== -->
  <target name="run.text" description="Run the unit tests in text mode">
    <java classname="junit.textui.TestRunner">	
      <arg line=" mypackage.MyScenarioJUnit"/> 
      <classpath refid="jrules.classpath" />
      <classpath path="${basedir}/bin/." />
      <classpath>
        <pathelement location="${basedir}/lib/xom.jar"/> 
      </classpath>
      <!-- Localization of scenarios files --> 
      <classpath path="${basedir}/data/scenario/." />
      <classpath path="${basedir}/data/scenario/reports/excel/." />
 
      <!-- Localization of the configuration and template files --> 
      <classpath path="${basedir}/config/." />
      <classpath path="${basedir}/templates/." />
 
    </java>
</target>

Note
The above can be used to execute scenario suites and simulations, replacing occurrences of Scenario in the code with ScenarioSuite or Simulation.

Related Concepts

Scenarios
Scenario Suites
Simulations

Related Tasks

Executing a Scenario, Scenario Suite, or Simulation
RSM Archives Execution with Ant Commands
RSM Archive Execution from an HTTP Client

Related Reference

Scenario XML Definition

Related Samples

How to Test Rules in Rule Scenario Manager Using Java Binding
How to Test Rules in Rule Scenario Manager using XML Binding