Sorry - I wrote this reply before realizing that you were asking about
an "editor", not just incorporating Drools into an RCP. I am posting
this in case other are having the more mundane problem of making a RCP
execute Drools rules.
- Mike
I have been trying to do this for a while, and have managed to create
an RCP that does work. I know at least one other person has responded
on this list as having accomplished it. His response indicated that
he created a separate plugin for all the Drools components, and
referred to it from his main plugin. He also indicated that the
objects needed for the DRL file had to be in the same plugin as the
Drools engine components.
This has not been my experience. I created a plugin that contains the
Drools components and the dependent jars in the /lib folder of the
Drools distribution. That plugin's Manifest.mf file must be edited to
add the line:
Eclipse-BuddyPolicy: registered
to the end because this will allow the plugin to access any other
plugins that want to be accessed by the Drools plugin. So suppose you
name your plugin MinimalDrools; the last line of the Manifest.mf
shows that it is registered as a Eclipse buddy.
Now export the plugin in a deployable format, and then drag the new
plugin into the Eclipse plugin folder and restart Eclipse.
Now your project plugin needs to depend on this newly added plugin.
In addition, in your project plugin Manifest.mf, you must add the
reciprocal part of the buddy registration:
Eclipse-RegisterBuddy: MinimalDrools
With this structure, I added a rules directory in the root of the
plugin, and in my application code:
private void fireDroolsRulesEngine() throws Exception {
GlucoseDecisionState decisionState = new GlucoseDecisionState();
Reader source;
final PackageBuilder builder = new PackageBuilder();
source = new InputStreamReader(FileLocator.toFileURL(
GlucosePlugin.getDefault().getBundle().getEntry(
"rules/GlucoseDroolRules00.drl")).openStream());
builder.addPackageFromDrl(source);
if (builder.hasErrors()) {
System.out.println(builder.getErrors().toString());
}
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
StatefulSession session = ruleBase.newStatefulSession();
// setup the debug listeners
session.addEventListener( new DebugAgendaEventListener() );
session.addEventListener( new DebugWorkingMemoryEventListener() );
// setup the audit logging
final WorkingMemoryFileLogger glucoseLogger = new
WorkingMemoryFileLogger( session );
glucoseLogger.setFileName( "glucoseLogFile" );
session.insert(decision,true);
session.insert(decisionState,true);
session.fireAllRules();
glucoseLogger.writeToDisk();
session.dispose();
}
This works. It is necessary to add the dependency of MinimalDrools to
you feature, etc. if you are exporting a complete application.
This being said, I cannot successfully run JUnit tests on the Drools
part of my RCP. I can unit test everything else, including things
like Hibernate, my database connections, etc. But the MinimalDrools
plugin does not satisfy some aspect of the Eclipse JUnit setup. The
Drools compiler does initialize, but something prevents the package
from instantiating (several previous posts on this that remain
unresolved).
Good luck.
Date: Sat, 08 Dec 2007 19:04:52 +0100
From: Michael Sizaki <Sizaki(a)gmx.de>
Subject: [rules-users] Drools and eclipse RCP
To: rules-users(a)lists.jboss.org
Message-ID: <475ADCC4.2080305(a)gmx.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi,
is it possible to use the drools editor etc in an eclipse RCP
application? At the moment, org.drools.eclipse plugin
depends on debug and jdt and other eclipse IDE related
plugins.....
I would want a simple way for users to enter rules into
my RCP application.
Michael