简体   繁体   English

Osgi eclipse:如何从片段包中导出包并使它们对外部包可见?

[英]Osgi eclipse: how to export package from a fragment bundle and make them visible to an external bundle?

Starter situation (without any error): 入门情况(没有任何错误):

  • I have three different bundles: bunbdle A (called org.apache.xmlbeans), bundle B and bundle C 我有三个不同的包:bunbdle A(称为org.apache.xmlbeans),bundle B和bundle C
  • bundle B import some packages exported from the bundle A bundle B导入从bundle A导出的一些包
  • bundle B export some packages (eg the package com.prova.xsd.config) bundle B导出一些包(例如包com.prova.xsd.config)
  • bundle C import the packages exported by the bundle B (eg the package com.prova.xsd.config) bundle C导入bundle B导出的包(例如包com.prova.xsd.config)

Now I make bundle B a fragment of the bundle A (fragment-host) adding the directive Fragment-Host: org.apache.xmlbeans in the MANIFEST of the bundle B 现在我将bundle B作为bundle A(fragment-host)的一个片段,在bundle B的MANIFEST中添加指令Fragment-Host:org.apache.xmlbeans

After this change there are NO errors in the MANIFEST.MF of all the bundles (A,B,C) but in the classes .java of the bundle CI have the compile error: "The import com.prova.xsd.config cannot be resolved" associated to the import at the head of the file .java. 在此更改之后,所有包(A,B,C)的MANIFEST.MF中都没有错误,但在包CI的类.java中有编译错误:“导入com.prova.xsd.config不能是已解决“与文件头部的导入相关联.java。

What is the problem? 问题是什么? How can I fix it? 我该如何解决?

Thanks a lot, 非常感谢,

Andrea 安德里亚

You need to add "Eclipse-ExtensibleAPI: true" to the Manifest of your host plugin A. 您需要在主机插件A的Manifest中添加“Eclipse-ExtensibleAPI:true”。

From Eclipse Help: OSGi Manifest Bundle : 来自Eclipse Help:OSGi Manifest Bundle

The Eclipse-ExtensibleAPI Header Eclipse-ExtensibleAPI标头

The Eclipse-ExtensibleAPI is used to specify whether a host bundle allows fragment bundles to add additional API to the host. Eclipse-ExtensibleAPI用于指定主机包是否允许片段包向主机添加其他API。 This header should be used if a host bundle wants to allow fragments to add additional packages to the API of the host. 如果主机包想要允许片段将其他包添加到主机的API,则应使用此标头。 If this header is not specified then a default value of 'false' is used. 如果未指定此标头,则使用默认值“false”。 Note that this header is only used by tooling (PDE) to construct proper class paths for building. 请注意,此标头仅供工具(PDE)用于构建正确的构建类路径。 The runtime does not use this header at all. 运行时根本不使用此标头。 At runtime a fragment is always allowed to add additional packages, classes and resources to the API of the host. 在运行时,始终允许片段将其他包,类和资源添加到主机的API。 The Eclipse-ExtensibleAPI header must use the following syntax: Eclipse-ExtensibleAPI标头必须使用以下语法:

Eclipse-ExtensibleAPI ::= ( 'true' | 'false' )

The following is an example of the Eclipse-ExtensibleAPI header: 以下是Eclipse-ExtensibleAPI标头的示例:

Eclipse-ExtensibleAPI: true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM