VRS simple interface <serialization 2>—Java class introduces jar package calling rule package

In addition to calling the rule package from the JSP page generated by the page configurator embedded in the rule configurator, if other java projects want to call this rule package, they can call it through the rule engine class. The following demonstrates how the java project in eclipse invokes the rule package.

Set the java project path
First , in the java project of eclipse, click Properties to set its path. Set Libraries in the Java Build Path of its properties window, add engine.jar and jakarta.jar under the lib under the VisualRulesSolution installation directory through Add External JARs…, and add the rules directory under the VisualRulesSolution installation directory through Add External Class Folder…. As shown below:




Add a Java test class Add a java class
to the java project named TestHello.java, whose content is edited as follows:
import com.flagleader.engine.RuleEngine;
import com.flagleader.engine.RuleEngineFactory;
public class TestHello {
public static void main(String[] args) {
try {
RuleEngine engine = RuleEngineFactory.newInstance().getRuleEngine(); engine.put
("name", "Access Test");
engine.execute("hello");// or engine.execute("hello.rsc"); hello or hello.rsc is its path under imported rules
System.out.println(engine.getString("welcome" ));
} catch (Exception e) {
e.printStackTrace() ;
}
}
}

Execute the java test class After
clicking execute, you can see the following results:








Figure 3-1-2-1-2 Code
means that the hello rule has been called package, and according to the incoming name value "access test", the returned processing result is hello+"access test".
Similarly, any other java class can complete the work of calling the rule package by adding the above code.



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326780656&siteId=291194637