Hi Wolfgang,
Thanks for picking this up. I am indeed compiling these separate .drl
files into separate .drl.compiled files and then creating a kbase using
addKnowledgePackages on the individual .drl.compiled files.
But: the classes declared in some of by .drl files are only going to be
used in that particular .drl file - not anywhere else.
Also: this did work in 5.4.0.Final but now has given up on me.
Point is that I need to be flexible in mixing different .drl.compiled
files into a kbase, based on user specifications.
Alternative is that I do not pre-compile these .drl files and only
compile them, in combination, in the mix that is required by the user...
If that would solve the problem... But it seems to be more cumbersome...
Regards,
Willem
On 10/24/2012 03:39 PM, Wolfgang Laun wrote:
The code you use for loading where you load many .pkg files
isn't
quite the counterpart for compiling where you compile one DRL.
Do you compile and output the .drl files one by one? Apparently you
load them individually?
Try compiling them all, and then take the Collection<KnowledgePackage>
and writeObject it to a single .pkg from which you load them in one
go.
Could it be that the type declared in one .drl is used in another .drl
in the same package? Reading this in the wrong order might cause the
CNF.
-W
On 24/10/2012, Willem van Asperen <willem(a)van.asperen.org> wrote:
> Dear All,
>
> I use the Drools compiler to compile a set of drl files:
>
>
> KnowledgeBuilder kbuilder =
> KnowledgeBuilderFactory.newKnowledgeBuilder(configuration);
> kbuilder.add(ResourceFactory.newFileResource(fileName),
> ResourceType.DRL);
>
> KnowledgeBuilderErrors errors = kbuilder.getErrors();
> if (errors.size() > 0) {
> for (KnowledgeBuilderError error: errors) {
> logger.error(error);
> }
> throw new IllegalArgumentException("Could not parse
> knowledge.");
> }
>
> ObjectOutputStream out = new ObjectOutputStream(new
> FileOutputStream(fileName+".compiled"));
> out.writeObject( kbuilder.getKnowledgePackages());
> out.close();
>
> I then load these *.compiled files into my application:
>
>
> for (String packageName : packages) {
> InputStream is =
> getClass().getResourceAsStream("/"+packageName+".drl.compiled");
> if (is != null) {
> logger.debug("adding package
'"+packageName+"'");
> ObjectInputStream in = new ObjectInputStream(is);
> kbase.addKnowledgePackages((Collection<KnowledgePackage>) in.readObject());
> in.close();
> } else
> throw new FileNotFoundException("could not find
> resource for package "+packageName);
> is.close();
> }
>
> In some of these drl files I declare a class, for instance:
>
> package vcm.selection.standard;
>
> import com.paconsulting.pase.transport.agents.ShiftWorker;
> import com.paconsulting.pase.transport.agents.VCMShiftWorker;
> import com.paconsulting.pase.transport.actions.ExecutableAction;
> import com.paconsulting.pase.transport.agents.ScheduleManagingContainer;
> import com.paconsulting.pase.transport.agents.water.Bridge;
> import com.paconsulting.pase.transport.agents.movers.AbstractMover;
> import com.paconsulting.pase.transport.agents.movers.Ship;
> import com.paconsulting.pase.transport.agents.movers.VCMShip;
>
> declare RelevantExecutableAction
> agent : ShiftWorker
> executableAction : ExecutableAction
> end
> ...
>
> When running the
> kbase.addKnowledgePackages((Collection<KnowledgePackage>)
> in.readObject()) I get the following ClassNotFound stack trace:
>
> java.lang.ClassNotFoundException:
> vcm.selection.standard.RelevantExecutableAction
> at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
> at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
> at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
> at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Class.java:264)
> 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:1593)
> at
> java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1514)
> at java.io.ObjectInputStream.readClass(ObjectInputStream.java:1480)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1330)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at
>
org.drools.rule.ConsequenceMetaData$Statement.readExternal(ConsequenceMetaData.java:61)
> at
> java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at java.util.ArrayList.readObject(ArrayList.java:733)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at
> java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
> at
> java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at
> org.drools.rule.ConsequenceMetaData.readExternal(ConsequenceMetaData.java:19)
> at
> java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at org.drools.rule.Rule.readExternal(Rule.java:207)
> at
> java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at
> org.drools.rule.JavaDialectRuntimeData.readExternal(JavaDialectRuntimeData.java:195)
> at
> java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at java.util.HashMap.readObject(HashMap.java:1155)
> at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at
> java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
> at
> java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at
> org.drools.rule.DialectRuntimeRegistry.readExternal(DialectRuntimeRegistry.java:58)
> at
> java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at org.drools.rule.Package.readExternal(Package.java:208)
> at
>
org.drools.definitions.impl.KnowledgePackageImp.readExternal(KnowledgePackageImp.java:157)
> at
> java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at java.util.ArrayList.readObject(ArrayList.java:733)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at
> java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
> at
> java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1866)
> at
> java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
> at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
> at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
> at
>
com.paconsulting.pase.core.configuration.runconfig.definition.KnowledgebaseDefinition.addPackages(KnowledgebaseDefinition.java:48)
> at
>
com.paconsulting.pase.core.configuration.runconfig.definition.KnowledgebaseDefinition.materialize(KnowledgebaseDefinition.java:59)
> at
>
com.paconsulting.pase.core.configuration.runconfig.definition.TeamDefinition.materialize(TeamDefinition.java:97)
> at
>
com.paconsulting.pase.core.configuration.runconfig.definition.OperatingModelDefinition.materialize(OperatingModelDefinition.java:36)
> at
> com.paconsulting.pase.core.configuration.runconfig.Run.<init>(Run.java:31)
> at
>
com.paconsulting.pase.core.configuration.runconfig.definition.RunDefinition.materialize(RunDefinition.java:53)
> at
>
com.paconsulting.pase.core.configuration.runconfig.RunConfigExecutor$ScheduleExecutorWrapper.run(RunConfigExecutor.java:69)
> ...
>
> I'm sure I miss something as this is basic functionality. Maybe I must
> tell the kbase where to load the classes...
>
> Can someone point me in the right direction?
>
> Thanks,
> Willem
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users