You'll have to provide your own classloader which can read resources
both from your .jar file and from where you keep your .drl files.
See java.net.URLClassLoader for how to do that. (Include two URLs: one
to your .jar, one where you keep the .drl files.) You can pass the
loader to the package builder.
Keep in mind that an absolute path in getResourceAsStream is relative
to each classpath entry in the classloader being used.
This is about all that's supported in Drools right now. I have opened
a JIRA enhancement request asking the JBoss developers to provide a
more flexible mechanism that allows both java code and drl files from
multiple sources to be loaded and combined, as was discussed on the
mailing list. I hope this issue may be addressed in the future as it
constitutes a real hindrance to using Drools in systems composed of
multiple rule providers.
On 10/10/07, Fermion <henss(a)physik.uni-wuppertal.de> wrote:
I've finished my first small application using JBoss Rules. My current
deployment "strategy" is that I want to have a single executable .jar file
containing my application and an external (not included in the .jar) folder
that contains the rules that should be used.
Unfortunately, this seems to be harder, than I thought, as my application
refuses to use .drl or .dsl files that are outside of the package.
I'm quite sure that it's just my misunderstanding of the manual that leads
to the problem, as this seems to be one of the most basic deployment
approaches, as stated by the manual:
Chapter 7. Deployment and Testing
7.1. Deployment options
Once you have rules integrated in your application (or ideally before) you
will need to plan how to deploy rules along with your application. Typically
rules are used to allow changes to application business logic without
re-deploying the whole application. This means that the rules must be
provided to the application as data, not as part of the application (eg
embedded in the classpath).
Unfortunately I have quite some problems understanding the rest of the
chapter. So I just used and modified on of the given examples.
//read in the source
Reader source = new
//read in the DSL
Reader dsl = new
//Use package builder to build up a rule package.
//An alternative lower level class called "DrlParser" can also be used...
PackageBuilder builder = new PackageBuilder();
//Use the following instead of above if you are using a DSL:
If I use
KNOWLEDGE_FILE = "/Rules_withDsl.drl";
DOMAINSPECIFICLANGUAGE_FILE = "/Rules_withDsl.dsl";
it all works wonderfully... but then the rules are within my .jar :-(
So I tried to change this into a folder outside the package:
KNOWLEDGE_FILE = "C:/test/Rules_withDsl.drl";
DOMAINSPECIFICLANGUAGE_FILE = "C:/test/Rules_withDsl.dsl";
Now, it doesn't work any more, because the "getResourceAsStream" returns
View this message in context:
Sent from the drools - user mailing list archive at Nabble.com
rules-users mailing list