Eclipse无法解析工作空间中其他项目的类

时间:2014-01-22 20:05:48

标签: eclipse osgi eclipse-rcp manifest buildpath

我正面临一个让我疯狂的问题。我在我的工作区中有一个项目,它在它的清单文件中导出一个包,如下所示:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Service
Bundle-SymbolicName: br.unicamp.cepetro.unisim.mero.service
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Unisim
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: br.unicamp.cepetro.unisim.mero.service
Require-Bundle: org.eclipse.swt;bundle-version="3.6.0",
 org.eclipse.equinox.common;bundle-version="3.6.0",
 org.eclipse.e4.core.services;bundle-version="0.9.1",
 org.eclipse.osgi;bundle-version="3.6.0",
 org.eclipse.e4.core.contexts;bundle-version="0.9.0",
 org.eclipse.core.resources;bundle-version="3.8.101"
Import-Package: javax.inject;version="1.0.0"

有趣的是:我有一个项目从导出的包中引用类很好,但另一个没有。构建路径显然没问题,eclipse甚至会自动将导入放在保存操作上,但它会以红色突出显示“导入XXX无法解析”。我已经尝试过清理项目,重新创建项目,从package-import更改为bundle import但没有成功。

有效的清单是:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Navigator
Bundle-SymbolicName: br.unicamp.cepetro.unisim.mero.navigator;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.core.resources;bundle-version="3.8.101",
 org.eclipse.swt;bundle-version="3.102.1",
 org.eclipse.e4.ui.workbench;bundle-version="1.0.1",
 org.eclipse.e4.core.di;bundle-version="1.3.0",
 org.eclipse.e4.ui.services;bundle-version="1.0.1",
 org.eclipse.jface;bundle-version="3.9.1",
 org.eclipse.equinox.common;bundle-version="3.6.200",
 org.eclipse.osgi;bundle-version="3.9.1",
 org.eclipse.core.databinding;bundle-version="1.4.1",
 org.eclipse.jface.databinding;bundle-version="1.6.200",
 org.eclipse.e4.core.commands;bundle-version="0.10.2",
 org.eclipse.e4.core.contexts;bundle-version="1.3.1",
 org.eclipse.e4.core.services;bundle-version="1.1.0",
 org.eclipse.e4.ui.model.workbench,
 org.eclipse.emf.common,
 org.eclipse.emf.ecore;bundle-version="2.9.1",
 org.eclipse.e4.ui.workbench.swt;bundle-version="0.12.1"
Import-Package: br.unicamp.cepetro.unisim.mero.model.mero,
 br.unicamp.cepetro.unisim.mero.service,
 javax.annotation;version="1.1.0",
 javax.inject;version="1.0.0"
Service-Component: OSGI-INF/serviceRegistryComponent.xml

不存在的清单是:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mero
Bundle-SymbolicName: br.unicamp.cepetro.unisim.mero;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Unisim
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.e4.ui.workbench.swt;bundle-version="0.12.1",
 org.eclipse.equinox.app;bundle-version="1.3.100",
 org.eclipse.e4.ui.css.swt.theme;bundle-version="0.9.100",
 org.eclipse.e4.core.di;bundle-version="1.3.0",
 org.eclipse.e4.ui.workbench;bundle-version="1.0.1",
 br.unicamp.cepetro.unisim.mero.model;bundle-version="1.0.0",
 org.eclipse.core.resources;bundle-version="3.8.101",
 org.eclipse.equinox.common;bundle-version="3.6.200",
 org.eclipse.e4.ui.services;bundle-version="1.0.1",
 org.eclipse.jface;bundle-version="3.9.1",
 org.eclipse.core.jobs;bundle-version="3.5.300",
 br.unicamp.cepetro.unisim.mero.service;bundle-version="1.0.0",
 org.eclipse.osgi;bundle-version="3.9.1",
 org.eclipse.core.runtime;bundle-version="3.9.0",
 org.eclipse.core.filesystem;bundle-version="1.4.0",
 org.eclipse.e4.core.services;bundle-version="1.1.0",
 org.eclipse.e4.core.contexts;bundle-version="1.3.1",
 org.eclipse.e4.ui.model.workbench;bundle-version="1.0.1",
 br.unicamp.cepetro.unisim.mero.i18n,
 org.eclipse.e4.ui.di;bundle-version="1.0.0"
Service-Component: OSGI-INF/serviceRegistryComponent.xml, OSGI-INF/defaultProjectService.xml, OSGI-INF/eclipseProjectImporterService.xml, OSGI-INF/imageServiceFunction.xml, OSGI-INF/nlsLookupFactoryService.xml
 OSGI-INF/defaultProjectService.xml
Bundle-ActivationPolicy: lazy
Import-Package: javax.inject;version="1.0.0"

感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

在正确解析的bundle中,您为服务包指定了Import-Pacakge,但在不工作的包中,您已经指定了对服务包的依赖(通过{{1 }})。有关差异的讨论,请参见When should I use Import-Package and when should I use Require-Bundle?

我怀疑您在第二个捆绑包中没有得到正确解析的原因是因为您指定的版本是Require-Bundle,但服务包的实际声明版本是1.0.0