ILOG JRules User Guide > Executing Rules > Tasks > Executing a Ruleset Using a Native Rule Engine > Setting the Classpath to Contain the XOM and the Rule Engine

You can set the classpath of your Java application to contain the XOM and the rule engine from within Rule Studio. You can also set the XOM classpath by creating your own class loader.

To set the XOM and rule engine classpath in Rule Studio:

  1. Right-click the Java project in the Rule Explorer, and select Properties in the shortcut menu.
  2. In the Properties dialog, select Java Build Path.
  3. Select the XOM reference:
    1. If the XOM references a Java project, select the Projects tab and select the XOM reference in the list of required projects.
    2. If the XOM references a JAR file or a class folder, select the Libraries tab and add the XOM reference to the list of required JARs and class folders.
  4. Click the Libraries tab, then click Add Variable.
  5. In the New Variable Classpath Entry dialog, select the Rule Studio installation directory then click Extend.
  6. In the Variable Extension dialog, open the <InstallDir>/studio/lib directory and select the following JAR files, then click OK:
  7. - bcel.jar
    - jrules-engine.jar
    - sam.jar
    The rule engine JARs appear in the list of JARs and class folders on the build path.
  8. Click OK again.

The XOM and rule engine classpath is now set and you can start writing a ruleset execution method.

You can also set the XOM classpath by creating your own class loader. An IlrReflect object uses a class loader to load the XOM classes when a rule is parsed. The class loader that is set is not the only one to be used; it is the one that is used in priority. If a class cannot be retrieved using the set class loader, the class loader used to load the IlrReflect class is used. The following methods are defined by the IlrObjectModel interface, which is implemented by IlrReflect.

package ilog.rules.bom;
 
public interface IlrObjectModel
{
  public ClassLoader getClassLoader();
  public void setClassLoader(ClassLoader classLoader);
}

Java classes can be loaded only after the class loader has been set.

Note
Only one class loader can be set. Since JDK 1.2, class loaders are supposed to delegate loading a class to the parent class loader.
Important
The class loader is lost if the IlrReflect object is serialized and then deserialized.

If you use Java serialization, you can use the following method to prevent the loss of the class loader:

public class IlrReflect
{
  public static void linkClassLoader(ObjectInputStream str,
                                     ClassLoader loader) { ... }
};

This method is called by passing the specific ObjectInputStream containing the IlrReflect to be deserialized, and specifying a class loader when the IlrReflect is read from the stream. The call must be placed before the IlrReflect is deserialized.

Note
The setClassLoader method cannot be called after the IlrReflect has been completely deserialized, as deserializing an IlrReflect often implies the loading of some Java classes, and the class loader must be set to be able to load them.

Related Concepts

Rule Engine

Related Tasks

Creating a Java Project for Rules
Writing a Ruleset Execution Method
Getting Notification During Ruleset Execution

Related Reference

Rule Engine API