Hi Amit,
this is a simple snippet from KnowledgeAgentTest.java.
String rule1 = "";
rule1 += "package org.drools.test\n";
rule1 += "global java.util.List list\n";
rule1 += "rule rule1\n";
rule1 += "when\n";
rule1 += "then\n";
rule1 += "list.add( drools.getRule().getName() );\n";
rule1 += "end\n";
String rule2 = "";
rule2 += "package org.drools.test\n";
rule2 += "global java.util.List list\n";
rule2 += "rule rule2\n";
rule2 += "when\n";
rule2 += "then\n";
rule2 += "list.add( drools.getRule().getName() );\n";
rule2 += "end\n";
//Creates a builder and add the 2 rules
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(rule1.getBytes()),
ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(rule2.getBytes()),
ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
//get the generated package (change this if you have more
than one package)
KnowledgePackage pkg = (KnowledgePackage) kbuilder
.getKnowledgePackages().iterator().next();
// writes the package to a file
FileOutputStream out = new
FileOutputStream("/tmp/myPackage.pkg");
try {
DroolsStreamUtils.streamOut(out, pkg);
} finally {
out.close();
}
Best,
2010/4/2 Amit Kumar <amitkumar(a)gmail.com>
Hi Folks,
I am trying to create a .pkg file (for probably faster loading) from a .drl
file
Does anybody has a code snippet which I can use. Am unable to find it in
javadocs.
Thanks
Amit
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Esteban Aliverti