Drools 9 with JDK 17 failed to execute KieContainer

We’re currently migrating drools 7 to drools 9 using JAVA 17 with two separate project, one for spring-boot and one for rules jar that generated a kjar in local m2. In drools 7 this works without any issue.

Both projects able to successfully build and run upon executing mvn: clean install and mvn spring-boot:run. The main problem happens when executing the generated jar. It seems that it cannot find the a valid kieModule in the classPath then defaults to a default artifact that doesn’t exist (more details below).

Here are the stacktrace:



  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.2)

2024-08-16T16:14:18.217+08:00  INFO 90138 --- [drools-test] [           main] com.drools.test.DroolsTestApplication    : Starting DroolsTestApplication v0.0.1-SNAPSHOT using Java 17.0.11 with PID 90138 (/Users/isaacjones/IdeaProjects/drools-test/target/drools-test-0.0.1-SNAPSHOT.jar started by isaacjones in /Users/isaacjones/IdeaProjects/drools-test)
2024-08-16T16:14:18.220+08:00  INFO 90138 --- [drools-test] [           main] com.drools.test.DroolsTestApplication    : No active profile set, falling back to 1 default profile: "default"
2024-08-16T16:57:12.607+08:00  INFO 90138 --- [drools-test] [           main] o.d.c.k.builder.impl.KieRepositoryImpl   : Adding KieModule from classpath: nested:/Users/isaacjones/IdeaProjects/drools-test/target/drools-test-0.0.1-SNAPSHOT.jar/!BOOT-INF/lib/drools-rules-test-2.0.0-SNAPSHOT.jar
2024-08-16T16:57:13.219+08:00  WARN 90138 --- [drools-test] [           main] o.d.c.k.b.impl.ClasspathKieProject       : Unable to find pom.properties in /Users/isaacjones/IdeaProjects/drools-test/target/drools-test-0.0.1-SNAPSHOT.jar/!BOOT-INF/lib/drools-rules-test-2.0.0-SNAPSHOT.jar
2024-08-16T16:57:13.249+08:00  WARN 90138 --- [drools-test] [           main] o.k.m.i.embedder.MavenSettings           : Environment variable M2_HOME is not set
2024-08-16T16:57:16.928+08:00  INFO 90138 --- [drools-test] [           main] o.d.c.k.b.impl.ClasspathKieProject       : Recursed up folders, found and used pom.xml /Users/isaacjones/IdeaProjects/drools-test/pom.xml
2024-08-16T16:57:16.930+08:00  INFO 90138 --- [drools-test] [           main] o.d.c.k.b.i.InternalKieModuleProvider    : Creating KieModule for artifact com.drools:drools-test:0.0.1-SNAPSHOT
2024-08-16T16:57:16.950+08:00  WARN 90138 --- [drools-test] [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kieContainer' defined in class path resource [com/drools/test/DroolsConfiguration.class]: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception with message: begin 50, end 49, length 49
2024-08-16T16:57:16.959+08:00  INFO 90138 --- [drools-test] [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-08-16T16:57:16.985+08:00 ERROR 90138 --- [drools-test] [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kieContainer' defined in class path resource [com/drools/test/DroolsConfiguration.class]: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception with message: begin 50, end 49, length 49
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:485) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1355) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.11.jar!/:6.1.11]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.11.jar!/:6.1.11]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.2.jar!/:3.3.2]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.2.jar!/:3.3.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.2.jar!/:3.3.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.2.jar!/:3.3.2]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.2.jar!/:3.3.2]
    at com.drools.test.DroolsTestApplication.main(DroolsTestApplication.java:10) ~[!/:0.0.1-SNAPSHOT]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91) ~[drools-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53) ~[drools-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58) ~[drools-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.kie.api.runtime.KieContainer]: Factory method 'kieContainer' threw exception with message: begin 50, end 49, length 49
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178) ~[spring-beans-6.1.11.jar!/:6.1.11]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:644) ~[spring-beans-6.1.11.jar!/:6.1.11]
    ... 25 common frames omitted
Caused by: java.lang.StringIndexOutOfBoundsException: begin 50, end 49, length 49
    at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4606) ~[na:na]
    at java.base/java.lang.String.substring(String.java:2709) ~[na:na]
    at java.base/java.lang.String.substring(String.java:2682) ~[na:na]
    at org.drools.compiler.kie.builder.impl.ZipKieModule.processEntry(ZipKieModule.java:189) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ZipKieModule.processZipEntries(ZipKieModule.java:173) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ZipKieModule.processFolderInZipFile(ZipKieModule.java:165) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ZipKieModule.processZipUrl(ZipKieModule.java:148) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ZipKieModule.processZipEntries(ZipKieModule.java:129) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ZipKieModule.indexZipFile(ZipKieModule.java:107) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ZipKieModule.<init>(ZipKieModule.java:55) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.InternalKieModuleProvider$DrlBasedKieModuleProvider.createKieModule(InternalKieModuleProvider.java:47) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.InternalKieModuleProvider.get(InternalKieModuleProvider.java:60) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ClasspathKieProject.createInternalKieModule(ClasspathKieProject.java:223) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:219) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:163) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.checkClasspathForKieModule(KieRepositoryImpl.java:185) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:132) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:115) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:190) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:178) ~[drools-compiler-9.44.0.Final.jar!/:9.44.0.Final]
    at com.drools.test.DroolsConfiguration.kieContainer(DroolsConfiguration.java:18) ~[!/:0.0.1-SNAPSHOT]
    at com.drools.test.DroolsConfiguration$$SpringCGLIB$$0.CGLIB$kieContainer$0(<generated>) ~[!/:0.0.1-SNAPSHOT]
    at com.drools.test.DroolsConfiguration$$SpringCGLIB$$FastClass$$1.invoke(<generated>) ~[!/:0.0.1-SNAPSHOT]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:258) ~[spring-core-6.1.11.jar!/:6.1.11]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:348) ~[spring-context-6.1.11.jar!/:6.1.11]
    at com.drools.test.DroolsConfiguration$$SpringCGLIB$$0.kieContainer(<generated>) ~[!/:0.0.1-SNAPSHOT]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146) ~[spring-beans-6.1.11.jar!/:6.1.11]
    ... 26 common frames omitted

Disconnected from the target VM, address: '127.0.0.1:52353', transport: 'socket'

drools-rules project pom


    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.drools</groupId>
    <artifactId>drools-rules-test</artifactId>
    <version>2.0.0-SNAPSHOT</version>
    <packaging>kjar</packaging>
    <name>drools-rules-test</name>
    <description>drools-rules-test</description>
    <properties>
        <java.version>17</java.version>
        <drools.version>9.44.0.Final</drools.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-internal</artifactId>
            <version>${drools.version}</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.kie</groupId>
                <artifactId>kie-maven-plugin</artifactId>
                <version>${drools.version}</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

drools-test project pom

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.drools</groupId>
    <artifactId>drools-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>drools-test</name>
    <description>drools-test</description>
    <properties>
        <java.version>17</java.version>
        <com.bpi.drools.rules.customerriskscoringrules.version>2.0.0-SNAPSHOT
        </com.bpi.drools.rules.customerriskscoringrules.version>
        <drools.version>9.44.0.Final</drools.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.drools</groupId>
            <artifactId>drools-rules-test</artifactId>
            <version>2.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>${drools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
            <version>${drools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>${drools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-mvel</artifactId>
            <version>${drools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
            <version>${drools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-xml-support</artifactId>
            <version>${drools.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

We have empty Kmodule.xml in Meta-INF folder

DroolsConfiguration

package com.drools.test;

import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.builder.ReleaseId;
import org.kie.api.runtime.KieContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DroolsConfiguration {

    @Bean
    public KieContainer kieContainer() {
        KieServices kieServices = KieServices.Factory.get();
        ReleaseId releaseId = kieServices.newReleaseId("com.drools", "drools-rules-test", "2.0.0-SNAPSHOT");

        KieContainer kieContainer = kieServices.newKieContainer(releaseId);
        KieScanner scanner = kieServices.newKieScanner(kieContainer);
        scanner.start(1000);
        return kieContainer;
    }
}

We’ve tried to replicate it and create a simple projects with simple rule jar to replicate the issue then debug it using intelliJ. We found that the drools-compiler dependency first look inside the classPath for kieModule then proceed to check local repository.

  URL kmoduleUrl = contextClassLoader.getResource( KieModuleModelImpl.KMODULE_JAR_PATH.asString() );

this line of code produces this path:

nested:/Users/isaacjones/IdeaProjects/drools-test/target/drools-test-0.0.1-SNAPSHOT.jar/!BOOT-INF/lib/drools-rules-test-2.0.0-SNAPSHOT.jar

due to wrong format for the classLoader the “!” in the .jar/!BOOT-INF and dependency lookup for the path it defaults to a default artifact that doesn’t exist.

        if (pomReleaseId.equals(releaseId)) {
            String path = pomPropertiesUrl.getPath();
            String pathToJar = path.substring( 0, path.indexOf( ".jar!" ) + 4 );

We’re expecting that the class loader able to produce this correct path in order to work and procced to check the .m2 repository for the jar.

nested:/Users/isaacjones/IdeaProjects/drools-test/target/drools-test-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/drools-rules-test-2.0.0-SNAPSHOT.jar

What causes the wrong contextClassLoader path for JAVA 17? since this not happens in JAVA 8 with drools 7.

Is there any missing kie or drools dependency in order to solve this issue?

Any help and answer is very much appreciated!

New contributor

Isaac Jones is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật