I recently we faced an issue in my Drools Config class where we added config for kie container and kie modules.
It was working fine in normal windows server environment but we migrated our app into docker environment we faced below error.
When running our Java Spring Boot app (Fat Jar) on Docker Environment we are getting below error:
Error: Failed to instantiate [org.kie.api.builder.KieModule]: Factory method 'kieModule' threw an exception; nested exception is java.lang.NullPointerException
Method in our Drools Config class:
@Bean(KieModule)
public KieModule kieModule() {
KieServices kservice = KieServices.Factory.get();
final KieRepository kr = kservice.getRepository(); //failing here
KieModule kieModule = new KieModule() {
public ReleaseId getReleaseId(){ return releaseId.getDefaultReleaseId();}
};
kieRepository.addKieModule(kieModule);
return kieModule;
}
}
build.gradle has following dependencies
implementation 'org.kie:kie-spring:7.30.0:Final'
implementation 'org.drools:drools-core:7.30.0:Final'
implementation 'org.drools:drools-compiler:7.30.0:Final'
The functionality works fine in JVM and other servers but when deployed in internal Docker container it breaks at KieRepository instance and gives null pointer exception.
Solved by appending the kie.conf files using shadow plugin in gradle.
The problem is that when you compile your jar you are overriding the META-INF/kie.conf
file.
Add following in your build.gradle:
dependencies{classpath("com.github.jengelman.gradle.plugins:shadow:4.0.4")}
apply plugin: 'com.github.johnengleman.shadow'
shadowJar{
manifest{
attribute('Main-Class': 'com.demo.HelloWorldApp')
}
append('META-INF/kie.conf')
}