简体   繁体   中英

Drools rule compilation error on upgrade to Java 7

I'm using Drools (5.5.0) rules in my Java project (managed using maven 2.2.1). It works fine in Java 6 (1.6.0_45), but when I move to Java 7 (1.7.0_51) and build, certain rules give a rule compilation error such as the following:

Rule Compilation error : [Rule name='SampleRuleName']
    com/sample/event/rules/simple/Rule_SampleRuleName46467274.java (2:486) : Syntax error, static imports are only available if source level is 5.0
    com/sample/event/rules/simple/Rule_SampleRuleName46467274.java (2:500) : The import com.sample.event.rules.simple.TransformEvent.transformEvent cannot be resolved
    com/sample/event/rules/simple/Rule_SampleRuleName46467274.java (7:1082) : The method transformEvent(TransformedEventCallBackHandler, EventTemplate, FirmwareEvent) is undefined for the type Rule_SampleRuleName46467274

The "static imports are only available if source level is 5.0" error suggests the drools compiler is setting a source level less than 5, but why would it do that? I've update my JAVA_HOME and my pom.xml. It should be picking up the Java source level from there, right?

Upgrade to Drools 6, this issue is fixed there. We had a similar issue for Java 8 recently with Drools 6.0 and it's fixed for 6.1 (and recent versions of 6.0 too).

The cause for java 8 was that drools recognizes java versions 1.6, 1.7, but not 1.8 at which point it defaults to 1.6. I suspect that drools 5.5 (which is old) had the same problem for java 7.

Turns out Drools uses the Eclipse JDT compiler to compile rules. Upgrading the JDT version did the trick. However if that fails, upgrading the Drools version might also help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM