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:
-
Build Rule and Java projects
-
Generate Ruleset Archives using an Extractor
-
Modify settings in your Eclipse environment:
-
Set a new extended model for the rules
-
Set the level of JDK compliance.
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:
-
Start Eclipse. In the Help menu click Software Updates > Manage Configuration.
-
Click Add an Extension Location.
-
Select the folder
<InstallDir>/studio/samples/eclipse and click OK.
-
Click Yes to restart Eclipse.
-
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:
-
Open the Import Wizard or in the File menu click Import.
-
In the Import Wizard select ILOG Rule Studio Samples and Tutorials, click Next and select samples > brmanagement > commandlinetool.
-
Click Finish.
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:
-
In the Rule Explorer open the project commandlinetool.
-
Double click build.properties to open it.
-
Set
eclipse.location to the path of your Eclipse installation. For example:
eclipse.location=C:/ILOG/JRules66/eclipse
To run the sample:
-
In the Window menu select Open Perspective > Other.
-
Select Resource and click OK.
-
In the Run menu select External Tools > Run External Tools.
-
In the left pane expand the Ant build tree and select commandlinetool-application.
-
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:
-
Settings have been modified in the target workspace:
-
JDK Compliance has been set to 1.5
-
The Eclipse Autobuild property is set to
false
-
A new Extended model has been set for rules
-
The following have been built:
-
The java project
rulesetextraction_xom
-
The rule project
rulesetextraction_rules
-
The
rulesetarchive has been created.
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
Related Tasks
Related Samples and Tutorials