[jboss-jira] [JBoss JIRA] (JBRULES-3388) KnowledgeAgent custom classloader not working for PKG resources
Herman Post (JIRA)
jira-events at lists.jboss.org
Wed Jul 11 19:25:12 EDT 2012
[ https://issues.jboss.org/browse/JBRULES-3388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12705570#comment-12705570 ]
Herman Post commented on JBRULES-3388:
--------------------------------------
I applied Esteban's fix to the 5.4-SNAPSHOT release and re-tested, and it fixes the problem.
> KnowledgeAgent custom classloader not working for PKG resources
> ---------------------------------------------------------------
>
> Key: JBRULES-3388
> URL: https://issues.jboss.org/browse/JBRULES-3388
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Components: drools-core
> Affects Versions: 5.3.1.Final
> Environment: Windows 7, Java7-5, JBoss AS7.1
> Reporter: Herman Post
> Assignee: Esteban Aliverti
> Labels: drools-core
>
> I believe there may be a bug when trying to use a custom class loader with the KnowledgeAgent and the KnowledgeBuilderConfiguration, and when the ChangeSet is a PKG resource.
> I have been trying to get the knowledge-agent-classloader sample from the new Drools Cookbook to work with a PKG resource. The sample works fine for a DRL resource, but when I convert it to use my fact jar, and a PKG resource containing my rules, which I downloaded from Guvnor, it throws a ClassNotFoundException for my fact model. If I put my fact model in the classpath, the error goes away and my rules can be added to the KnowledgeAgent and run correctly. Following is the code from the sample that I have converted, and I have attached a zip file with a complete project demonstrating the problem. Also, I can get my rules and fact model to work if I use a DRL ChangeSet.knowledge-agent-classloader.zip
> URL modelJarURL = getClass().getResource("Patient-1.0.jar");
> URLClassLoader customURLClassloader = new URLClassLoader(new URL[] {modelJarURL });
> KnowledgeBuilderConfiguration kbuilderConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
> customURLClassloader);
> KnowledgeBaseConfiguration kbaseConfig = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, customURLClassloader);
> KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
> KnowledgeAgentConfiguration aconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
> KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent("test", kbase, aconf, kbuilderConfig);
> // kagent.applyChangeSet(new ClassPathResource("change-set.xml", getClass())); // this goes with model.jar
> // kagent.applyChangeSet(new ClassPathResource("drl-change-set.xml", getClass())); // this goes with Patient.jar
> kagent.applyChangeSet(new ClassPathResource("pkg-change-set.xml", getClass())); // this goes with Patient.jar
> return kagent.getKnowledgeBase();
> Following is the stack trace from the error:
> java.lang.NullPointerException
> at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:148)
> at org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1016)
> at org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:785)
> at org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:657)
> at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:190)
> at org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:169)
> at drools.cookbook.chapter02.KnowledgeAgentClassloaderTest.createKnowledgeBase(KnowledgeAgentClassloaderTest.java:59)
> at drools.cookbook.chapter02.KnowledgeAgentClassloaderTest.customClassloaderTest(KnowledgeAgentClassloaderTest.java:30)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
> at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
> at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
> at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
> at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
> at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
> at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
> at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
> at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
> at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
> at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
> at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> I have been having the exact same problem when trying to use a custom class loader with just a KnowldegeBuilder and no KnowledgeAgent.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list