Samples > Rule Studio Business Rule Management Extensions > How to Use the Rule Studio Command Line Tool

JRules provides a command line tool that allows you to automate routine operations from the command line. The command line tool launches Rule Studio in headless mode (with no user interface for the development environment) to run specified JavaScript files.

This sample shows you how to use the command line tool to build a project and create a ruleset archive.

Key Features

Key features include:

Importing this Sample

This sample extends the Rule Studio API and the required sample plug-ins are delivered as pre-deployed. You must therefore install the samples extension site in Eclipse before running the sample.

To install the samples extension site:

  1. Start Eclipse. In the Help menu click Software Updates > Manage Configuration.
  2. Click Add an Extension Location.
  3. Select the folder <InstallDir>/studio/samples/eclipse and click OK.
  4. Click Yes to restart Eclipse.
  5. In the File menu click Switch Workspace and specify a new workspace directory. Eclipse will exit and restart automatically with a blank workspace.

To import the sample:

  1. Open the Import Wizard or in the File menu click Import.
  2. In the Import Wizard select ILOG Rule Studio Samples and Tutorials, click Next and select samples > brmanagement > commandlinetool.
  3. Click Finish.
  4. The required sample project files are imported.

If one or more files already exist in your workspace, a warning message is displayed indicating that the corresponding file(s) were not re-imported.

The imported sample project files are displayed in the Rule Explorer. You should see a new project commandlinetool.

Running the Sample

Before running the sample, you may need to set the location of your Eclipse installation.

To set the location of your Eclipse installation:

  1. In the Rule Explorer open the project commandlinetool.
  2. Double click build.properties to open it.
  3. Set eclipse.location to the path of your Eclipse installation. For example:
  4. eclipse.location=C:/ILOG/JRules66/eclipse

To run the sample:

  1. In the Window menu select Open Perspective > Other.
  2. Select Resource and click OK.
  3. In the Run menu select External Tools > Run External Tools.
  4. In the left pane expand the Ant build tree and select commandlinetool-application.
  5. In the right pane click the Run button. In the stdout console you should see:
[java] [Thu Mar 29 11:20:30 CEST 2007] Script Execution Started
[java] [Thu Mar 29 11:20:30 CEST 2007] JDK Compliance set to 1.5
[java] [Thu Mar 29 11:20:33 CEST 2007] Build workspace cleaned : *workspace.location*
[java] [Thu Mar 29 11:20:34 CEST 2007] Autobuilding set to false
[java] [Thu Mar 29 11:20:34 CEST 2007] Setting model brmx.location *brdx.location *
[java] [Thu Mar 29 15:37:53 CEST 2007] Extracting ruleset archive
rulesetextraction_rules with extractor 'Custom Extractor'
[java] [Thu Mar 29 15:37:56 CEST 2007] Successfully extracted in
workspace.location \rulesetextraction_rules.jar
[java] [Thu Mar 29 11:35:59 CEST 2007] ====== rulesetextraction_rules OK ==========
[java] [Thu Mar 29 11:35:59 CEST 2007] ====== rulesetextraction_xom OK ==========
[java] [Thu Mar 29 11:35:59 CEST 2007] Script Execution Ended

This indicates that:

Highlights

The javascript file in commandlinetool/scripts/importBuildExtract.js contains the following:

Table 1 Contents of javascript
Class/Function 
Description 
Utilities 
A class helper to print on the standard output. 
Arguments 
A class representing argument passed to the script. 
BuildReport 
A class representing build report for a project. 
WorkSpace 
A class wrapper to clean and manage the workspace. 
ArchiveBuilder 
A class wrapper to build/print build report/export ruleset. 
main 
The entry point of the script. 

When writing a script you have access to a predefined set of variables. Refer to Command-Line Global Variables for more information about predefined variables.

Ant Script

The JavaScript is launched by an Ant file located at commandlinetool/application/build.xml. It contains the following:

Table 2 Contents of build.xml
Target/Macro Definition 
Description 
init.runtime 
Intialize the runtime properties. 
init 
Intialize the properties used by the ant script. 
headless.application 
Defines a macro to easily launch the javascript script. 
executeScript 
Launch the java script with the help of the macro. 

The Ant script uses a property file build.properties that contains values passed to the macro when the script is launched.

Table 3 Content of build.properties
Properties 
Description 
workspace.location 
The folder of the workspace into which the projects will be exported. 
projectsfolder.location 
The folder of the projects that have to be built and used for the ruleset archive creation. 
script.location 
The location of the javascript. 
brmx.location 
The location of the extended model file. 
brdx.location 
The location of the data extended model file. 
extractor.name 
The name of the extractor used creating the ruleset archive. 
cleanworkspace.value 
Set to true if you want to delete the workspace content before running the javascript; set to false otherwise. 

Related Concepts

Rule Studio Command-Line Tool

Related Tasks

Using the Rule Studio Command-Line Tool
Command-Line Global Variables

Related Samples and Tutorials

How to Extract a Ruleset from a Rule Project