Maven Tycho构建中CategoryPublisher找不到org.eclipse.core.runtime bundle
问题根因
你直接通过-jar参数启动单独的org.eclipse.equinox.launcher包时,Equinox运行时默认只会加载launcher本身,不会自动扫描加载CategoryPublisher运行所需的全部依赖bundle(包括报错提到的org.eclipse.core.runtime和所有p2核心组件),也没有默认的bundle启动级别配置,框架启动后找不到对应的应用服务,就会抛出你看到的异常。
最优解决方案(Tycho原生支持,无兼容问题)
完全不需要自己写exec命令调用equinox launcher,Tycho官方已经封装了p2仓库构建、分类发布的全流程能力,不会出现OSGi依赖缺失的问题:
- 把当前模块的packaging类型改为
eclipse-repository
<packaging>eclipse-repository</packaging>
- 删除你之前配置的
exec-maven-plugin里所有和publish-category相关的执行逻辑 - 在build配置中加入
tycho-p2-repository-plugin,插件会自动读取模块根目录下的category.xml,在package阶段自动完成分类发布、p2仓库组装:
<plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-repository-plugin</artifactId> <version>${tycho.version}</version> <configuration> <compress>true</compress> </configuration> <executions> <execution> <id>publish-repository</id> <phase>package</phase> <goals> <goal>publish-repository</goal> </goals> </execution> </executions> </plugin>
特殊场景下保留exec调用的修复方案
如果因为项目限制必须保留手动调用launcher的方式,需要补全OSGi运行的必要参数,告诉Equinox插件目录位置和核心bundle启动规则:
- 在启动参数中新增
-install参数,指向tycho-bundles-external下的eclipse根目录,让Equinox能扫描到对应plugins目录下的所有bundle - 新增
-configuration参数指向构建目录下的独立配置文件夹,避免和其他构建任务冲突 - 调整后的核心启动参数片段如下,原有application、categoryDefinition、metadataRepository参数保留即可:
<argument>-install</argument> <argument>${settings.localRepository}/org/eclipse/tycho/tycho-bundles-external/${tycho.version}/eclipse/</argument> <argument>-configuration</argument> <argument>${project.build.directory}/equinox-temp-config/</argument> <argument>-consolelog</argument>
注意:这种手动维护OSGi启动参数的方案兼容性很差,Tycho版本升级后很容易因为依赖路径、bundle版本变化再次报错,非必要不使用。
内容的提问来源于stack exchange,提问作者BetaRide
相关产品推荐
相关产品推荐

