The ClassPath resource should be relative to the classpath root, i.e. include the
"packages"/subfolders.
So, "builder.add(ResourceFactory.newClassPathResource("General.drl"),
ResourceType.DRL)" won't probably work
if the DRL is in a subpackage.
Likewise,
"builder.add(ResourceFactory.newClassPathResource(getClass().getResource("General.drl").getFile()),
ResourceType.DRL)"
results in an absolute path
"/home/ste/workspace2/REC-mv/target/classes/rec/reasoner/" which is outside the
scope of the jar.
Can you try something like "/rec/reasoner/General.drl" - possibly without the
leading "/"?
Davide
On 07/18/2013 10:04 AM, sottostee wrote:
Hi everyone,
I have got a problem that me go mad.
Clarify I'm working with a Maven project using Eclipse.
I'm trying to add at my KnowledgeBuilder, after i have correctly created a
new instance of it, a drl file.
In order of this, i call a method: void
org.drools.builder.KnowledgeBuilder.add(Resource arg0, ResourceType arg1),
give it like a Resource "ResourceFactory.newClassPathResource(String: name
of my drl)" and like ResourceType: "ResourceType.DRL".
As long as i run my project into Eclipse, all works well.
But, if i create a jar file of my project, when i run this, i have this
exception:
java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:204)
at
org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:145)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:477)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at rec.reasoner.Reasoner.init(Reasoner.java:192)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
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:616)
at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.io.FileNotFoundException: 'General_multivalue.drl' cannot be
opened because it does not exist
at
org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:165)
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:177)
... 20 more
line 192 is properly:
'builder.add(ResourceFactory.newClassPathResource("General.drl"),
ResourceType.DRL);'
Well....given that in my project I've got some classes which make use of
images, and given that, in this classes I call this method:
getClass().getResource(String of image).getFile() in order to load the
images, and all seems work very well; therefore I'm doing the same thing
with drl file:
I change the old method with:
builder.add(ResourceFactory.newClassPathResource(getClass().getResource("General.drl").getFile()),
ResourceType.DRL);
Now:
1) when i run jar file, the exception is:
java.lang.NullPointerException
at rec.reasoner.Reasoner.init(Reasoner.java:189)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
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:616)
at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
2) and when i run the project into Eclipse, the exception is:
java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:204)
at
org.drools.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:145)
at org.drools.compiler.DrlParser.parse(DrlParser.java:139)
at
org.drools.compiler.PackageBuilder.drlToPackageDescr(PackageBuilder.java:477)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at
org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at
org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
at rec.reasoner.Reasoner.init(Reasoner.java:189)
at rec.reasoner.Reasoner.<init>(Reasoner.java:176)
at rec.reasoner.Reasoner.newReasoner(Reasoner.java:51)
at rec.model.Model.<init>(Model.java:37)
at rec.controller.Controller.<init>(Controller.java:26)
at applet.Demo.<init>(Demo.java:18)
at applet.Demo.main(Demo.java:36)
Caused by: java.io.FileNotFoundException:
'/home/ste/workspace2/REC-mv/target/classes/rec/reasoner/General_multivalue.drl'
cannot be opened because it does not exist
at
org.drools.io.impl.ClassPathResource.getURL(ClassPathResource.java:165)
at
org.drools.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:177)
... 15 more
but in '/home/ste/workspace2/REC-mv/target/classes/rec/reasoner/' the file
'General_multivalue.drl' EXISTS!!!!
Are there anyone who help me please?
Thanks in advance.
sotto
--
View this message in context:
http://drools.46999.n3.nabble.com/Unable-to-get-LastModified-for-Classpat...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users