You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Gradle的Eclipse RCP:org.eclipse.e4.core.di的bnd Import-Package指令失效

解决Eclipse RCP项目Java 11升级后javax.annotation.PostConstruct找不到的问题

问题分析

报错ClassNotFoundException: javax.annotation.PostConstruct cannot be found by org.eclipse.e4.core.di_1.8.200.v20220512-1957,查看org.eclipse.e4.core.di的Manifest可以看到:它通过Require-Bundle声明了对javax.annotation bundle的依赖,但Import-Package未包含javax.annotation包。Java 11已移除JDK自带的javax.annotation模块,必须通过独立bundle或API依赖提供该包。

解决方案

1. 确保javax.annotation bundle被正确引入

先检查Gradle依赖配置,确认是否包含符合版本要求的javax.annotation bundle,在build.gradle中添加或确认以下依赖:

dependencies {
    implementation 'org.eclipse.platform:javax.annotation:1.3.500.v20220513-1637'
    // 保留其他原有依赖
}

该版本匹配org.eclipse.e4.core.di Manifest中要求的[1.3.5,2.0.0)版本范围。

2. 修正bnd配置的生效方式

你之前的bnd配置未正确作用到目标bundle,可尝试以下两种配置方式:

方式一:全局bnd配置

在项目根目录的bnd.bnd文件中添加全局导入规则:

Import-Package: javax.annotation;version="[1.3.0,2.0.0)", *

或者在Gradle的bnd插件配置中全局设置:

tasks.withType(BndOsgi) {
    bnd('Import-Package: javax.annotation;version="[1.3.0,2.0.0)", *')
}

方式二:针对特定依赖的bnd配置

若需单独修改org.eclipse.e4.core.di的导入规则,通过Gradle的解析策略绑定bnd指令:

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == 'org.eclipse.platform' && details.requested.name == 'org.eclipse.e4.core.di') {
            details.useVersion '1.8.200.v20220512-1957'
            details.target.bnd('Import-Package: javax.annotation;version="[1.3.0,2.0.0)", *')
        }
    }
}

3. 替代方案:使用标准javax.annotation-api依赖

若bundle方式不生效,可直接引入标准API依赖并通过bnd强制导入:

dependencies {
    implementation 'javax.annotation:javax.annotation-api:1.3.2'
}

同时在bnd配置中添加:

Import-Package: javax.annotation;version="[1.3.0,2.0.0)", *

4. 检查运行环境插件配置

确保Eclipse运行配置中包含javax.annotation bundle:

  • 打开Run Configurations -> 选择你的RCP应用 -> 切换到Plug-ins标签
  • 搜索javax.annotation,勾选该插件为Selected状态

内容的提问来源于stack exchange,提问作者Sunny Onesotrue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 07:12:04