[rules-users] How to read DRL files not in resource classpath?

Daniel Souza danieldsouza15 at gmail.com
Wed Jun 13 11:49:31 EDT 2012


At ResourceFactory you have the methods:
  ResourceFactory.*newUrlResource*("http://localhost:8080/rules/myRule.drl")
 
ResourceFactory.*newClassPathResource*("your-project-path/path-rules/myRule.drl")
  ResourceFactory.*newFileResource*("C:\path-rules\myRule.drl")

  you have other methods, you can use InputStream, Reader and others.
  you can mix the recources. You can get an resource in the Web with
newUrlResource, you can get your resource inside your class path, you can
get the resource in your filesystem and mix all resources to build your
knowledge base.

A sample code to show this mix:
  KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
  //kbuilder.add( ResourceFactory.newUrlResource(
droolsResourceMap.get("blastManagerRule") ), ResourceType.DRL );
  *kbuilder.add(
ResourceFactory.newClassPathResource("domain/BiologistDomain.dsl"),
ResourceType.DSL );
  kbuilder.add(ResourceFactory.newUrlResource(resource), ResourceType.DSLR
);*
  if (kbuilder.hasErrors()) {
    System.err.println(kbuilder.getErrors().toString());
  }
			
  KnowledgeBase kbase = kbuilder.newKnowledgeBase();
  kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());

  // here you start your knowledge session

--
View this message in context: http://drools.46999.n3.nabble.com/How-to-read-DRL-files-not-in-resource-classpath-tp4017885p4017918.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list