Eclipse无法从工作区中的另一个项目解析类

时间:2022-04-17 11:15:58

I am facing an issue that is driving me crazy in here. I have a project in my workspace that exports a package in it's manifest file like this:

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

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"

The funny thing is: I have one project that references classes from the exported package just fine, but the other one does not. The build path is apparently ok, eclipse even put the imports automatically on save actions but it gets highlighted in red saying "import XXX cannot be resolved". I've already tried cleaning the projects, re-creating the project, change from package-import to bundle import but with no success.

有趣的是:我有一个项目引用了来自导出包的类,但另一个项目没有。构建路径显然是ok的,eclipse甚至将导入自动地放到save操作上,但它被突出显示为红色,表示“无法解析import XXX”。我已经尝试过清理项目,重新创建项目,从包导入更改到包导入,但是没有成功。

The manifest for the one that works is:

工作者的舱单是:

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

The manifest for the one that does not is:

没有的人的清单是:

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"

Any help is appreciated.

任何帮助都是感激。

1 个解决方案

#1


2  

In the bundle that is resolving correctly, you've specified an Import-Pacakge for the service package, but in the one that isn't working you've specified a dependency on the service bundle (via Require-Bundle). See When should I use Import-Package and when should I use Require-Bundle? for some discussion about the differences.

在正确解析的包中,您已经为服务包指定了一个Import-Pacakge,但是在无效的包中,您已经指定了对服务包的依赖关系(通过Require-Bundle)。看看我什么时候应该使用进口包装,什么时候应该使用需求包装?关于差异的一些讨论。

I suspect the reason you are not getting correct resolution in the second bundle is because the version you've specified is 1.0.0 but the service bundle's actual declared version is 1.0.

我怀疑您在第二个bundle中没有得到正确的解析是因为您指定的版本是1.0.0,但是服务bundle的实际声明版本是1.0。

#1


2  

In the bundle that is resolving correctly, you've specified an Import-Pacakge for the service package, but in the one that isn't working you've specified a dependency on the service bundle (via Require-Bundle). See When should I use Import-Package and when should I use Require-Bundle? for some discussion about the differences.

在正确解析的包中,您已经为服务包指定了一个Import-Pacakge,但是在无效的包中,您已经指定了对服务包的依赖关系(通过Require-Bundle)。看看我什么时候应该使用进口包装,什么时候应该使用需求包装?关于差异的一些讨论。

I suspect the reason you are not getting correct resolution in the second bundle is because the version you've specified is 1.0.0 but the service bundle's actual declared version is 1.0.

我怀疑您在第二个bundle中没有得到正确的解析是因为您指定的版本是1.0.0,但是服务bundle的实际声明版本是1.0。