Hi,
While trying to get some integration tests of the Maven Drools
Plugin green for 5.2.0.Final and 5.3.0.Beta1, I'm getting weird
behaviour of the newer Drools version when it comes to deserializing
KnowledgePackages.
What do I do in the code?
- compile three *.drl files (see below)
- serialize the resulting KnowledgePackages using
DroolsStreamUtils.streamOut(new FileOutputStream(outputFile),
knowledgeBuilder.getKnowledgePackages(), false) from within the
plugin (see [1], [2])
- de-serialize the knowledge packages using
DroolsStreamUtils.streamIn(new FileInputStream(file)) in a TestNG
test [3], using [4]
- I get java.lang.ClassNotFoundException for a declared data type:
java.lang.ClassNotFoundException: model.Age
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at
org.drools.common.DroolsObjectInputStream.resolveClass(DroolsObjectInputStream.java:85)
at
org.drools.common.DroolsObjectInputStream.resolveClass(DroolsObjectInputStream.java:97)
at
java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
at
java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
Strangely enough, the same code works well if I switch to Drools
5.1.1. What changed between 5.1.1 and 5.2.0.Final that might cause
this effect? Might I be doing something wrong using
DroolsStreamUtils?
Would be happy about any hints.
Thank you in advance.
Here are the three input files, which get compiled exactly in this
order:
1) Person.drl
package model;
declare Person
name: String
end
2) Age.drl
package model;
declare Age
person: Person
age: Integer
end
3) minimum-age.drl:
package rules;
dialect "mvel"
import model.Person;
import model.Age;
rule "check minimum age"
when
Age( $person: person, age < 18 )
then
insertLogical("TOO YOUNG: " + $person.name )
end
Best regards
Ansgar
[1] https://github.com/maven-drools/plugin.maven-drools-plugin/blob/57c77fce26ceac41256e7f70c4e4daa2f411de4f/mojos/src/main/java/de/lightful/maven/plugins/drools/impl/OutputFileWriter.java
[2] https://github.com/maven-drools/plugin.maven-drools-plugin/blob/57c77fce26ceac41256e7f70c4e4daa2f411de4f/mojos/src/main/java/de/lightful/maven/plugins/drools/mojos/CompileMojo.java
[3] https://github.com/maven-drools/plugin.maven-drools-plugin/blob/57c77fce26ceac41256e7f70c4e4daa2f411de4f/generic-integration-test-bundle/src/test/java/de/lightful/maven/plugins/drools/integrationtests/CanPerformMultiplePassesTest.java
[4] https://github.com/maven-drools/plugin.knowledge-io/blob/a89bcf581d75b2ac8dfd55122c140568dbb8756a/src/main/java/de/lightful/maven/plugins/drools/knowledgeio/KnowledgePackageFile.java