Upgrade from Drools 7 to 9

65 views
Skip to first unread message

Cris N

unread,
Jun 17, 2024, 8:26:30 AMJun 17
to Drools Setup
Hello,

I have a project built with Spring Boot 2, Java 11 and Drools 7, deployed in PCF (Pivotal Cloud Foundry).
I'm trying to upgrade this project to Spring Boot 3, Java 17 and Drools 9.


I replaced the following dependencies:
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>7.16.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>7.16.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>7.16.0.Final</version>
</dependency>

With:
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>9.44.0.Final</version>
</dependency>

<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-engine-classic</artifactId>
<version>9.44.0.Final</version>
</dependency>

Locally the app starts correctly and loads the rule, but when I deploy the app to PCF, I get errors like:

java.lang.NoClassDefFoundError: org/drools/mvel/accessors/BaseIntClassFieldReader\n\tat java.base/java.lang.ClassLoader.defineClass1(Native Method)\n\tat java.base/java.lang.ClassLoader.defineClass(Unknown Source)\n\tat org.drools.wiring.dynamic.DynamicComponentsSupplier$DefaultByteArrayClassLoader.defineClass(DynamicComponentsSupplier.java:68)\n\tat org.drools.mvel.asm.ClassFieldAccessorFactory.getClassFieldReader(ClassFieldAccessorFactory.java:96)\n\tat org.drools.mvel.asm.ClassFieldAccessorFactory.getClassFieldReader(ClassFieldAccessorFactory.java:50)\n\tat org.drools.core.base.ClassFieldAccessorCache$CacheEntry.getReadAccessor(ClassFieldAccessorCache.java:178)\n\tat org.drools.core.base.ClassFieldAccessorCache.getReadAccessor(ClassFieldAccessorCache.java:100)\n\tat org.drools.mvel.accessors.ClassFieldAccessorStore.wire(ClassFieldAccessorStore.java:279)\n\tat org.drools.mvel.accessors.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:112)\n\tat org.drools.mvel.accessors.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:90)\n\tat org.drools.mvel.MVELKnowledgePackageImpl.getReader(MVELKnowledgePackageImpl.java:113)\n\tat org.drools.compiler.rule.builder.PatternBuilder.getFieldReadAccessor(PatternBuilder.java:1791)\n\tat org.drools.compiler.rule.builder.PatternBuilder.getFieldReadAccessor(PatternBuilder.java:1755)\n\tat org.drools.compiler.rule.builder.PatternBuilder.buildConstraintForPattern(PatternBuilder.java:1167)\n\tat org.drools.compiler.rule.builder.PatternBuilder.buildRelationalExpression(PatternBuilder.java:1114)\n\tat org.drools.compiler.rule.builder.PatternBuilder.buildExpression(PatternBuilder.java:983)\n\tat org.drools.compiler.rule.builder.PatternBuilder.buildCcdDescr(PatternBuilder.java:955)\n\tat org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:765)\n\tat org.drools.compiler.rule.builder.PatternBuilder.processConstraintsAndBinds(PatternBuilder.java:609)\n\tat org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:177)\n\tat org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:143)\n\tat org.drools.compiler.rule.builder.PatternBuilder.build(PatternBuilder.java:125)\n\tat org.drools.compiler.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:66)\n\tat org.drools.compiler.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:36)\n\tat org.drools.compiler.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:66)\n\tat org.drools.compiler.rule.builder.RuleBuilder.build(RuleBuilder.java:98)\n\tat org.drools.compiler.builder.impl.processors.ImmutableRuleCompilationPhase.internalAddRule(ImmutableRuleCompilationPhase.java:339)\n\tat org.drools.compiler.builder.impl.processors.ImmutableRuleCompilationPhase.addRule(ImmutableRuleCompilationPhase.java:334)\n\tat org.drools.compiler.builder.impl.processors.ImmutableRuleCompilationPhase.compileRulesLevel(ImmutableRuleCompilationPhase.java:298)\n\tat org.drools.compiler.builder.impl.processors.ImmutableRuleCompilationPhase.process(ImmutableRuleCompilationPhase.java:82)\n\tat java.base/java.util.Arrays$ArrayList.forEach(Unknown Source)\n\tat org.drools.compiler.builder.impl.KnowledgeBuilderImpl.compileKnowledgePackages(KnowledgeBuilderImpl.java:461)\n\tat org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addPackageWithResource(KnowledgeBuilderImpl.java:446)\n\tat org.drools.compiler.builder.impl.KnowledgeBuilderImpl.addKnowledgeResource(KnowledgeBuilderImpl.java:377)\n\tat org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:919)\n\tat org.drools.compiler.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:908)\n\tat com.garmin.ecommerce.drools.manager.KnowledgeWrapper.add(KnowledgeWrapper.java:22)\n\tat com.garmin.ecommerce.drools.manager.KnowledgeBaseFactory.lambda$fromPartitionedRules$3(KnowledgeBaseFactory.java:60)\n\tat java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)\n\tat java.base/java.util.stream.ReferencePipeline$2$1.accept(Unknown Source)\n\tat java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(Unknown Source)\n\tat java.base/java.util.stream.AbstractPipeline.copyInto(Unknown Source)\n\tat java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)\n\tat java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)\n\tat java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)\n\tat java.base/java.util.stream.AbstractPipeline.evaluate(Unknown Source)\n\tat java.base/java.util.stream.ReferencePipeline.forEach(Unknown Source)\n\tat com.garmin.ecommerce.drools.manager.KnowledgeBaseFactory.lambda$fromPartitionedRules$4(KnowledgeBaseFactory.java:60)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(Unknown Source)\n\tat java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(Unknown Source)\n\tat java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)\n\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)\n\tat java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)\n\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)\n\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)\nCaused by: java.lang.ClassNotFoundException: org.drools.mvel.accessors.BaseIntClassFieldReader\n\tat java.base/java.lang.ClassLoader.findClass(Unknown Source)\n\tat java.base/java.lang.ClassLoader.loadClass(Unknown Source)\n\tat

And:

Could not add Rule=rule1, errors -> Unable to resolve ObjectType 'LoopControl' : [Rule name='05c66cd8-a87d-49c7-b225-f70e0163b50a']\n\nUnable to resolve ObjectType 'Country'
............
Failed to compileShared: 1 compilation error(s): \n - (1,16) could not resolve class: LoopControl]\n[Near : {... drools.insert( new LoopControl( \"05c66cd8-a87 ....}]\n ^\n[Line: 27, Column: 0] : [Rule name='05c66cd8-a87d-49c7-b225-f70e0163b50a']\n\nError importing :


Any idea what dependency I'm missing and why those classes are not accessible at runtime?

Thank you,
Cristina

Ajay Chowdary Kandula

unread,
Jun 18, 2024, 5:19:45 PMJun 18
to cristi...@gmail.com, drools...@googlegroups.com
## Issue Analysis The errors you're encountering are related to missing dependencies or classes when running your application on Pivotal Cloud Foundry (PCF). The `NoClassDefFoundError` and `ClassNotFoundException` indicate that the JVM is unable to find certain classes at runtime, which are likely part of the Drools library. The specific errors you're seeing are: 1. `java.lang.NoClassDefFoundError: org/drools/mvel/accessors/BaseIntClassFieldReader`: This class is part of the Drools MVEL (MVEL is a rule engine and scripting language used by Drools) package, which seems to be missing in your PCF deployment. 2. `Unable to resolve ObjectType 'LoopControl'` and `Unable to resolve ObjectType 'Country'`: These errors suggest that the Drools engine is unable to find the classes `LoopControl` and `Country` during rule compilation. These classes might be part of your domain model or custom classes used in your Drools rules. ## Potential Solutions 1. **Check Dependency Versions**: Ensure that the Drools dependency versions you're using are compatible with Spring Boot 3 and Java 17. The versions you've provided (`9.44.0.Final`) should be compatible, but it's worth double-checking the official documentation or release notes for any known issues or compatibility concerns. 2. **Include Additional Drools Dependencies**: You might need to include additional Drools dependencies to resolve the missing classes. For example, you could try adding the following dependencies: ```xml <dependency> <groupId>org.drools</groupId> <artifactId>drools-mvel</artifactId> <version>9.44.0.Final</version> </dependency> <dependency> <groupId>org.drools</groupId> <artifactId>drools-model-compiler</artifactId> <version>9.44.0.Final</version> </dependency> ``` The `drools-mvel` dependency should resolve the `BaseIntClassFieldReader` issue, and the `drools-model-compiler` dependency might help with resolving custom classes used in your rules. 3. **Check Class Visibility**: Ensure that the classes `LoopControl` and `Country` are visible to the Drools engine. If these are part of your domain model, make sure they are included in the same package or module as your Drools rules, or that they are properly imported or referenced in your rules. 4. **Verify Deployment Configuration**: Double-check your deployment configuration and settings for PCF. Ensure that all required dependencies and classes are included in the deployment package and that there are no conflicts or issues with the deployment environment or settings. 5. **Enable Debugging**: Enable debugging in your PCF deployment to get more detailed information about the errors and the classes that are causing issues. This can help you identify the root cause more precisely. 6. **Check for Updates and Known Issues**: Check for any updates or known issues related to Drools, Spring Boot, or Java versions you're using. Sometimes, compatibility issues or bugs are addressed in newer versions or patches. If none of these solutions work, you might need to provide more information about your project structure, deployment process, and any additional configurations or customizations you've made to help identify the root cause of the issue. Sources


Thanks and Regards!!!
Ajay C. Kandula


--
You received this message because you are subscribed to the Google Groups "Drools Setup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-setup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/46e8e626-7b21-4ab6-b01b-e9f1bac52a73n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages