'Optaplanner - drools file cannot be compiled when project is deployed

We developped a SpringBoot project with Java 11 using optaplanner-core and defining rules in a Drools file. We have no issue for running the app in intelliJ with JDK.

We then deployed the app onto Azure app service where a JRE is installed. We get the following error:

Caused by: org.kie.memorycompiler.KieMemoryCompilerException: 
Cannot find the System's Java compiler. Please use JDK instead of JRE or add drools-ecj dependency to use in memory Eclipse compiler

We tried to add the following dependencies but we still get the same error:

<dependency>
    <groupId>org.optaplanner</groupId>
    <artifactId>optaplanner-core</artifactId>
    <version>8.4.1.Final</version>
</dependency>
<dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-ecj</artifactId>
    <version>7.51.0.Final</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jdt</groupId>
    <artifactId>ecj</artifactId>
    <version>3.26.0</version>
</dependency>

Would anyone know how to solve this problem ?

Thank you



Solution 1:[1]

Adding drools-ecj won't really fix this. The error message is misleading.

Using a JDK instead of a JRE. The easiest way is to upgrade to Java 11 (or higher), as that only comes with a JDK.

Solution 2:[2]

If running optaplanner with a JDK is no option for you, you can change the solver config to

<solver>
  <scoreDirectorFactory>
    <droolsAlphaNetworkCompilationEnabled>false</droolsAlphaNetworkCompilationEnabled>
  </scoreDirectorFactory>
</solver>

and if you're using unit tests for java constraints that use the ConstraintVerifier, instantiate it like this

new DefaultConstraintVerifier<>(new MyConstraints(), SolutionDescriptor.buildSolutionDescriptor(myModelClasses))
  .withDroolsAlphaNetworkCompilationEnabled(false)

However: From what I understood, disabling the drools alpha network compiler usually comes with a performance impact.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Geoffrey De Smet
Solution 2 thimmwork