Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-3630

ClassPathResources within ChangeSet are loaded using wrong ClassLoader

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 5.4.1.Final, 5.5.0.Beta1
    • 5.1.1.FINAL, 5.4.0.Final
    • drools-core
    • None
    • Hide

      Create a JAR containing a change-set.xml and a DRL file (e.g. as above), and load this JAR file into the application using URLClassLoader.

      ClassLoader classLoader = URLClassLoader.newInstance(new URL[] { ...url to JAR file ... }, getClass().getClassLoader());
      Resource changeSet = ResourceFactory.newClassPathResource("change-set.xml", classLoader);
      KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, classLoader);
      KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
      builder.add(changeSet, ResourceType.CHANGE_SET);
      
      Show
      Create a JAR containing a change-set.xml and a DRL file (e.g. as above), and load this JAR file into the application using URLClassLoader . ClassLoader classLoader = URLClassLoader.newInstance( new URL[] { ...url to JAR file ... }, getClass().getClassLoader()); Resource changeSet = ResourceFactory.newClassPathResource( "change-set.xml" , classLoader); KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration( null , classLoader); KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf); builder.add(changeSet, ResourceType.CHANGE_SET);

    Description

      I am trying to load a "rules" JAR dynamically. This JAR contains a change-set.xml and all of its DRL files:

      <?xml version="1.0" encoding="UTF-8"?>
      <change-set xmlns='http://drools.org/drools-5.0/change-set'
          xmlns:xs='http://www.w3.org/2001/XMLSchema-instance'
          xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd'>
          <add>
              <resource source='classpath:com/my/stuff/rules/Stuff.drl' type='DRL' />
          </add>
      </change-set>
      

      I am loading the JAR dynamically via URLClassLoader and successfully creating the ChangeSet resource:

      Resource changeSet = ResourceFactory.newClassPathResource("change-set.xml", classLoader);

      However, it then always explodes when I try to add the resource to the KnowledgeBuilder, complaining that "'com/my/stuff/rules/Stuff.drl' cannot be opened because it does not exist".

      I am suspecting that the KnowledgeBuilder is not using my class loader to load Stuff.drl, despite me passing the correct class loader in via KnowledgeBuilderConfiguration. (And the "changeset:" handling in org.drools.xml.changeset.ResourceHandler would seem to support my theory.)

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            chrisjr_jira Chris Rankin (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

            Dates

              Created:
              Updated:
              Resolved:
              Archived:

              PagerDuty