*Hi
I am trying to learn drools. Please help me with this problem. I am using
the HelloWorldExample from drools5.0 examples.
I have converted the HelloWorld.drl to HelloWorld.xml using the XmlDumper
class as follows: *
final Reader source = new InputStreamReader(
HelloWorldExample.class.getResourceAsStream( "HelloWorld.drl" ) );
Reader source = new InputStreamReader(fis );
final DrlParser drlp= new DrlParser();
final PackageDescr astx = drlp.parse(source);
String hope = new String();
XmlDumper xmldumper = new XmlDumper();
hope = xmldumper.dump(astx);
System.out.print(hope);
try {
FileWriter fw = new FileWriter(new File("d://HelloWorld.xml"));
fw.write(hope);
fw.flush();
fw.close();
} catch (IOException e){
}
*Then i am trying to load it as follows: *
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.xml",
HelloWorldExample.class), ResourceType.XDRL);
// Check the builder for errors
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException("Unable to compile
\"HelloWorld.drl\".");
}
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs = kbuilder
.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge
packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
*When i try to run this example, i am getting the error*
null: 5, 77): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 5, 77): cvc-elt.1: Cannot find the declaration of element 'package'.
(null: 6, 64): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 8, 51): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 12, 26): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 13, 47): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 15, 6): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 15, 53): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 16, 39): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 17, 50): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 20, 60): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 27, 12): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 31, 30): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 32, 47): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 34, 6): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 34, 38): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 35, 39): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 36, 50): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 39, 60): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 46, 12): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd';, because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
Unable to create a Field value of type 'ValueType = 'int'' and value
'Message.HELLO ' : [Rule name='Hello World']
java.lang.NoSuchFieldException: HELLO Unable to create restriction
'[QualifiedIndentifierRestr: == Message.HELLO ]' for field 'status' in
the
rule 'Hello World' : [Rule name='Hello World']
Unable to create a Field value of type 'ValueType = 'int'' and value
'Message.GOODBYE ' : [Rule name='Good Bye']
java.lang.NoSuchFieldException: GOODBYE Unable to create restriction
'[QualifiedIndentifierRestr: == Message.GOODBYE ]' for field 'status' in
the rule 'Good Bye' : [Rule name='Good Bye']
Exception in thread "main" java.lang.RuntimeException: Unable to compile
"HelloWorld.drl".
at org.drools.examples.HelloWorldExample.main(HelloWorldExample.java:36)
*I have included the drools5.0 runtime in the classpath of the project and
workspace. Am i missing something?
Is it the right way to load the rules in xml format to KnowledgeBuilder? Is
there an alternate way? Please HELP!
thanks
Abarna*