Hi everybody.
I am having a problem to instantiate a console application with Drools and Sping. With Spring, I am able to instanciate a bean and print its value to console, but with Spring + Drools I get this error:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kbase': Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to parser Reader
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
at java.security.AccessController.doPrivileged(Native Method)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.test.Test.main(Test.java:10)
Caused by: java.lang.RuntimeException: Unable to parser Reader
at org.drools.compiler.DrlParser.getParser(DrlParser.java:313)
at org.drools.compiler.DrlParser.parse(DrlParser.java:141)
at org.drools.compiler.DrlParser.parse(DrlParser.java:147)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:263)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:458)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:519)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:28)
at org.drools.container.spring.beans.KnowledgeBaseBeanFactory.afterPropertiesSet(KnowledgeBaseBeanFactory.java:103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 15 more
Caused by: java.lang.NullPointerException
at java.io.FilterInputStream.close(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream.close(Unknown Source)
at sun.nio.cs.StreamDecoder.implClose(Unknown Source)
at sun.nio.cs.StreamDecoder.close(Unknown Source)
at java.io.InputStreamReader.close(Unknown Source)
at org.antlr.runtime.ANTLRReaderStream.load(ANTLRReaderStream.java:92)
at org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:68)
at org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:52)
at org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:48)
at org.antlr.runtime.ANTLRInputStream.<init>(ANTLRInputStream.java:40)
at org.drools.compiler.DrlParser.getParser(DrlParser.java:308)
... 24 more
I use eclipse, and running from the IDE Spring + Drools in a console application works fine. This problem happens when I generate an executable jar and try the "java -jar" command.
My main method is below
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("appConfig.xml");
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) context.getBean("ksession");
System.out.println(ksession);
}
And my applicationContext.xml is below
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:drools="http://drools.org/schema/drools-spring"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://drools.org/schema/drools-spring http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-container/drools-spring/src/main/resources/org/drools/container/spring/drools-spring-1.0.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<drools:kbase id="kbase">
<drools:resources>
<drools:resource source="classpath:knowledgebase-config.xml" type="CHANGE_SET" />
</drools:resources>
</drools:kbase>
<drools:ksession id="ksession" type="stateful" kbase="kbase" />
</beans>
Any clue of what is cousing the problem? Thank you very much.
Regards,
Anderson