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