升级Eclipse与JDK后Drools Kie-Api导入失败及Maven异常求助
问题梳理
- 环境变更:将Eclipse从Neon升级至2023-12(4.30.0),同时把Java从1.8升级到23,全新安装配置后,原正常运行的JUnit项目出现异常
- 核心问题:
- 代码报错
The import org.kie cannot be resolved,Eclipse建议修复的Drools版本为7.14,与项目实际需要的7.44.0.Final-redhat-00003不符 - 本地Maven依赖大量缺失且变灰(同事环境正常,仅JDK、Eclipse版本不同)
- 执行
mvn -X package时,maven-surefire-plugin:2.12.4报错,提示分叉VM异常终止
- 代码报错
- 已尝试无效操作:修改依赖scope为Compile、手动添加缺失依赖库、配置JDK1.8为执行环境、添加Kie-Api依赖(解决导入错误但pom报错)、多次执行Maven Clean/Install/Update
解决方案
1. 修复Maven依赖缺失问题
- 检查Eclipse的Maven配置,确保使用本地正确的Maven安装(而非Eclipse内置版本):
路径:Window > Preferences > Maven > Installations,添加本地安装的Maven(推荐3.6.x及以上版本,适配JDK1.8+) - 强制更新Maven依赖并刷新项目:
右键项目 →Maven > Update Project,勾选Force Update of Snapshots/Releases后确定 - 在Maven的
settings.xml中添加Red Hat仓库配置(因为项目使用Red Hat定制的Drools版本):
在<repositories>节点下添加:
同时在<repository> <id>redhat-ga</id> <url>https://maven.repository.redhat.com/ga/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository><pluginRepositories>节点下同步添加该仓库配置
2. 解决JDK版本兼容性问题
- 在项目的
pom.xml中明确指定编译、运行的JDK版本为1.8(Drools 7.44.x对JDK23兼容性不足,且同事环境用1.8正常):
在<properties>节点添加:<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.release>1.8</maven.compiler.release> - 配置项目执行环境为JDK1.8:
右键项目 →Properties > Java Build Path > Libraries,移除JDK23并添加JDK1.8;切换到Java Compiler标签,勾选Use compliance from execution environment 'JavaSE-1.8' on the 'Java Build Path'
3. 修复Surefire插件分叉VM异常
- 升级
maven-surefire-plugin版本到兼容JDK1.8的版本,比如3.0.0-M5:
在pom.xml的<build><plugins>节点中更新配置:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M5</version> <configuration> <forkCount>1</forkCount> <reuseForks>false</reuseForks> <argLine>-Xmx1024m</argLine> </configuration> </plugin> - 若仍报错,可在配置中添加
<useSystemClassLoader>false</useSystemClassLoader>,避免类加载冲突
4. 统一Drools/Kie依赖版本
- 确保
pom.xml中所有Drools、Kie相关依赖版本统一为7.44.0.Final-redhat-00003,示例配置:<dependency> <groupId>org.drools</groupId> <artifactId>drools-core</artifactId> <version>7.44.0.Final-redhat-00003</version> </dependency> <dependency> <groupId>org.kie</groupId> <artifactId>kie-api</artifactId> <version>7.44.0.Final-redhat-00003</version> </dependency> - 不要单独手动添加Kie-Api依赖,避免版本冲突导致pom报错
内容的提问来源于stack exchange,提问作者javalearner
相关产品推荐
相关产品推荐

