To be able to run your application in a web container,
you must package a rule session JAR file for Java™ SE.
About this task
You must package the rule session JAR file for Java SE if you intend to run your application
in a web container, such as Tomcat or
Liberty. To
do so, you edit the deployment descriptor for your application and
the execution unit (XU) descriptor
ra.xml, and
you add the rule session JAR file and the other relevant files into
a web application archive (WAR) file.
Important: For customized Java SE applications that run on
a Tomcat or Liberty server,
declare each embedded XU with a unique xuName.
For example, xuName=xuMyAppName.
Note: By
default, the persistence type is the same for Java XOM resources as for rulesets.
Procedure
To package the Java rule
sessions for Java SE:
- Write the Java classes
to create a rule session and pass the data to the rule engine.
Use the rule session factory API in your ruleset execution
code (IlrJ2SESessionFactory).
- Optional: Configure the ra.xml deployment
descriptor for datasource persistence.
To
do so, set the ruleset persistence type and activate the XU MBean
in the ra.xml deployment descriptor. The ra.xml file
is in the <InstallDir>/executionserver/bin directory.
You can edit it from any text editor.
- Set the ruleset persistence type to datasource.
<config-property>
<config-property-name>persistenceType</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>datasource</config-property-value>
</config-property>
- Initialize the data source by setting the persistenceProperties value
as in the following example.
<config-property>
<config-property-name>persistenceProperties</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>JNDI_NAME=jdbc/resdatasource</config-property-value>
</config-property>
- Activate the XU MBean, which is necessary with the management
console, by changing the value of the plugins property.
<config-property>
<config-property-name>plugins</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>{pluginClass=Management,xuName=default},
{pluginClass=DVS},
{pluginClass=HTDS}
</config-property-value>
</config-property>
- Add the ra.xml file to the WEB-INF/classes directory
of your web application.
- Package the .class, .jsp and .html files
into a web application archive (WAR).
You can operate
any repackaging, but the goal is to grant access to the classes inside
your servlet or JavaServer Pages (JSP). If your rules rely on a Java XOM, package them in the WAR
file, in the WEB-INF/lib directory.
- Put the Java rule
session JAR file jrules-res-execution.jar and
execution unit (XU) descriptor ra.xml file in
the WEB-INF/lib directory.
Example
Packaging libraries for the execution
stack in a web application
Here is an example that uses an Ant script:
<import file="${executionserver.home}/lib/classpath-executionserver.xml"/>
<target name="war">
<war warfile="myapplication.war" webxml="descriptors/web.xml">
<!-- Classes of your web application -->
<classes dir="classes" />
<!-- The ra.xml file configured to use the data source provider -->
<classes file="descriptors/ra.xml" />
<!-- JAR for the Rule Execution
Server in Java SE -->
<lib dir="${executionserver.home}/lib/">
<patternset refid="executionserver.j2se.classpath.patternset" />
</lib>
</war>
</target>