Are the classes you import in your DRL available on the classpath at
runtime?
On 24 October 2012 11:10, 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