OpenRules release
3.0.0 is a major release that essentially simplifies the
configuration and integration of OpenRules.
Below we describe
how to move your projects created with previous OpenRules releases (2.3
and earlier) to the release 3.0.0.
Major Changes to Consider During Migration
The major changes are related to the fact
that OpenRules no longer uses Ant-based configuration files.
So, you do not need any more ANT-based configuration files, property files,
or environment variables. Your rules repository can be located
anywhere in your local file system and/or include Excel and XML files from
remote locations.
OpenRules no longer includes projects lib.ant, jacarta-tomcat,
jacarta-tomcat-deployer, and lib.axis. We assume that you have Ant
already installed. You also may use your own installation of Apache
Tomcat and Axis (if you need them). All jars-files you may need for
the configuration of OpenRules projects are now located in the directory
openrules.config/lib. There are only there jars files that include
OpenRules specific software:
- openrules.all.jar
- com.openrules.tools.jar
- com.openrules.java.eval.jar
You will definitely need openrules.all.jar. The com.openrules.tools.jar
is needed if you use an optional library of convenience Java methods.
The com.openrules.java.eval.jar is a new jar that is
needed only if you want to add a batch rules
validator to your non-Eclipse projects. All other jars inside openrules.config/lib are commonly
available under Open Source licenses. There are a few build-files
inside openrules.config that are used for the convenience of OpenRules
sample projects but you do not need them in run-time.
After the installation of the Release 3.0.0,
you may get rid of the old configurations files and add the proper
references to the table "Environment" in your main Excel-files.
In new sample projects most rules are located in a separate
subdirectory "rules". A program that invokes rules refers to the main
xls-file using prefix notation such as "file:", "classpath:", "http://",
"ftp://", etc. For example,
in the HelloJava project, the location is defined as a string
"file:rules/main/HelloCustomer.xls" that means that the main file
HelloCustomer.xls is located in the subdirectory "rules/main" of the base
project directory.
The changes you have to make to the existing OpenRules
projects are minimal but necessary. Please make sure that you save
your working OpenRules installations before installing a new release.
If for some reasons you need to download a previous OpenRules release again,
you can find one at http://openrules.com.
Automatic Migration of Eclipse Projects
If you work inside Eclipse IDE, OpenRules provides a new
Eclipse plug-in called "com.openrules.converter" that converts your
old Eclipse projects to OpenRules-3. Right-click on your old OpenRules
project and choose "Convert to OpenRules-3". The plugin will
automatically make the proper changes to your ".project" file and will add
OpenRules nature to it.
How To Migrate a Basic Rule Project
First compare the structure of the old and new sample
project HelloJava. Here are instructions for moving an old project to
a new one. You can make similar changes in your own project.
- Remove package src/com.openrules
- Remove files src/openrules.properties and src/openrules.java.build.xml
- Create a folder "rules" in your project base directory. Create a
subfolder "rules/main" and copy into it your main xls-file. If you
use Eclipse right-click on the folder "rules/main" and select Build Path
+ Use as Source Folder.
- Copy your old folder's "include" with all included xls-files into
"rules".
- In your Java program that invokes rules (such as
RunHelloCustomer.java) add the prefix "file:rules/main/" before the name
of the main xls-file. For example: String fileName =
"file:rules/main/HelloCustomer.xls";
- In your main xls-files you have to modify the table
"Environment". Look at the file HelloCustomer.xls from the sample
project HelloJava. It demonstrates two ways to refer to the included xls-files.
In most cases, you would prefer to define your included xls-files
relative to the
directory where your main xls-file is located. In the HelloJava
example, the main file "rules/main/HelloCustomer.xls" refers to the
included file "rules/include/HelloRules.xls" by using the attribute
"include" with the value "../include/HelloRules.xls". Another way
to do it is to define first a new attribute "include.path" as
"../include/" and set references to all included files relative to this
path using corner brackets like <HelloRules.xls>. See more details
at the new section Rules Repository.
- If your xls-files use some Java classes, you should
add a new attribute "import.java" inside the table "Environment". For
example, HelloCustomer.xls uses a custom Java package "hello". So, the
Environment table contains an attribute "import.java" with the value
"hello.*". It makes all classes from the package "hello" visible
to all xls-files from this project. You also can list certain Java
classes only by name, e,g. "hello.Customer". HelloJava project
also uses the standard OpenRules package com.openrules.tools. In
particular, it uses static methods such as out(message) from the Java
class com.openrules.tools.Methods. That’s why the Environment
table also includes another new attribute “import.static” with the value
“com.openrules.tools.Methods”.
- If your xls-files use some XML files to define new
data types, you should define a new attribute "import.schema" inside the
table "Environment". For example, the sample project
HelloXMLCustomer uses the file Customer.xml that resides in the project
classpath (subdirectory “bin” in this case). So, the Environment
table contains an attribute "import.schema" with the value
“classpath:/Customer.xml”.
How To Migrate a Web Application
OpenRules installation no longer includes the Tomcat-based project "jakarta-tomcat"
and "jakarta-tomcat-deployer". In most practical cases, people who
develop web application use their own Tomcat installations (or other web
application servers). OpenRules 3.0.0 standard examples demonstrate
how to work with Apache Tomcat 5.5.17 or WebSphere WAS 6.1.
We will use a sample project HelloForms to compare web applications for
OpenRules 2.* and OpenRules-3. Here are instructions for moving an old
project to a new one. You can make similar changes to your own
project. We will use one directory “war” that will contain all rules, jsp,
and xml files.
- Create a subdirectory "war/rules/main" and move here
the main xls-file HelloWeb.xls to it.
- Create separate subdirectories war/rules/data,
war/rules/logic, and war/rules/gui and move into them the included files
HelloData.xls, HelloRules.xls, and HelloForms.xls correspondingly.
- Remove src/openrules.properties, src/openrules.java.build.xml,
and subdirectory src/com/openrules.
- Modify the file war/index.jsp that invokes
OpenRulesEngine. Now this engine is created automatically by an
instance of OpenRulesSession in the following way:
String xlsMain = "file:../webapps/HelloForms/rules/HelloWeb.xls";
String s_attr = "openrules_session";
OpenRulesSession openrules_session =
(OpenRulesSession) session.getAttribute(s_attr);
if (openrules_session == null )
{
openrules_session = new OpenRulesSession(xlsMain);
session.setAttribute( s_attr, openrules_session);
System.out.println("NEW SESSION");
}
Usually jsp-files are similar for most web applications and you only
need to change the location of your main xls-file defined by the
variable xlsMain. In this case we use the prefix “file:” to point to the
fact that our main file HelloWeb.xls is deployed on the Tomcat server
and is located in the subdirectory “/webapps/HelloForms/rules”.
This subdirectory is located on the same level as Tomcat’s base
directory “bin” from where Tomcat starts. You can have different
locations of your main xls-files for different web servers.
- Modify the table "Environment" in you main xls-file
HelloWeb.xls. Now the attribute “include” is described with three
sub-rows:
../data/HelloData.xls
../logic/HelloRules.xls
../gui/HelloForms.xls
These correspond to the locations of our three included xls-files
relative to the directory of the main HellWeb.xls file. The
attribute “import.static” points to the class
com.openrules.tools.Methods from the standard OpenRules package
com.openrules.tools. We need this attribute because our xls-files
use standard static methods such as “out(message)”.
- Modify the build.xml. Now you can run the
target “build” to create HelloForms.war file and the target “deploy” to
deploy this file to the Tomcat server described in the build.properties.
How To Migrate a Web Service
OpenRules installation no longer includes project "lib.axis" and we assume
that you have Apache Axis 1.4 pre-installed. We will use a sample
project HelloWS to compare web services for OpenRules 2.* and OpenRules-3.
Similarly to a basic rules project, we should move all xls-files
in the directory war/rules and remove old configuration files and
properties.
Similarly to a web application, we will deploy a rule service HelloWS on the
Apache Tomcat 5.5.17 pre-installed by a customer. The locations of
Apache Tomcat and Axis are described in the file "build.properties".
We also need to modify the build.xml. Now you have
three targets to run: