Drools 不支持 Java 7(“RuntimeDroolsException: value '1.7' is not a valid language level”)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7837663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:38:09  来源:igfitidea点击:

No support for Java 7 in Drools ("RuntimeDroolsException: value '1.7' is not a valid language level")

javadroolsjava-7rule-engine

提问by Bala

While I'm moving my project to java7, Drools starting throwing RuntimeDroolsException exception during init process. When i dig further, I found that this is happening when it validates java dialect.

当我将我的项目移动到 java7 时,Drools 在初始化过程中开始抛出 RuntimeDroolsException 异常。当我进一步挖掘时,我发现当它验证 java 方言时会发生这种情况。

The problem is: Drools 5.1.1 compares "java.version" system property with LANGUAGE_LEVELS to validate it. LANGUAGE_LEVELS is hard-coded list of java versions till 1.6

问题是:Drools 5.1.1 将“java.version”系统属性与 LANGUAGE_LEVELS 进行比较以验证它。LANGUAGE_LEVELS 是 Java 版本的硬编码列表,直到 1.6

In org.drools.rule.builder.dialect.java.JavaDialectConfiguration,
public static final String[]        LANGUAGE_LEVELS = new String[]{"1.5", "1.6"};

I didn't want to change the source code. So I added the below as a workaround to bypass java dialect validation.

我不想更改源代码。所以我添加了以下作为绕过java方言验证的解决方法。

Properties properties = new Properties();
properties.setProperty( "drools.dialect.java.compiler.lnglevel","1.6" );
PackageBuilderConfiguration cfg =
new PackageBuilderConfiguration( properties );
KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(cfg);

Is there any better way of doing this other than editing source code?

除了编辑源代码之外,还有什么更好的方法可以做到这一点?

P.S: Drools 5.1.1 is the latest production version of the drools

PS:Drools 5.1.1是drools的最新生产版本

采纳答案by Bala

This is fixed in 5.2.1.FINAL version

这在 5.2.1.FINAL 版本中已修复

https://issues.jboss.org/browse/JBRULES-3163

https://issues.jboss.org/browse/JBRULES-3163

回答by CHristian Bonami

When you still want to use Drools 5.1.1(switching to a higher version is not always easy because rules do not compile anymore), this might be another, non-programmatic workaround.

当您仍想使用时Drools 5.1.1(切换到更高版本并不总是那么容易,因为规则不再编译),这可能是另一种非程序化的解决方法。

In META-INF/drools.packagebuilder.confyou can add these properties:

META-INF/drools.packagebuilder.conf您可以添加这些属性:

 drools.dialect.java.compiler = ECLIPSE 
 drools.dialect.java.lngLevel = 1.6 
 drools.dialect.java.compiler.lnglevel = 1.6

回答by ellisbjohns

I solved the above problem by replacing my referenced drools-complier.jar with the 5.4.0.Final version. I tried earlier releases of this jar but the same error resulted. This updated jar can be downloaded from the drools maven repo

我通过用 5.4.0.Final 版本替换我引用的 drools-complier.jar 解决了上述问题。我尝试了这个 jar 的早期版本,但结果是同样的错误。这个更新的 jar 可以从drools maven repo下载

回答by Manfred Moser

The best way would be submitting a patch to the project itself and helping them support Java 7 as well and then upgrading to that version once it is available.

最好的方法是向项目本身提交补丁并帮助他们支持 Java 7,然后在该版本可用后升级到该版本。