转载:OSGI组件依赖

简介: 原文链接: OSGi组件依赖     OSGi doesn’t allow you to specify class visibility at the class level, but instead at the level of the containing package. 1. The header:Export-Package and The directives for the Export-Package header     当指定一个package export,默认的它的subpackage是没有exportde,需特别指定。

原文链接:

OSGi组件依赖

    OSGi doesn’t allow you to specify class visibility at the class level, but instead at the level of the containing package.

1. The header:Export-Package and The directives for the Export-Package header

    当指定一个package export,默认的它的subpackage是没有exportde,需特别指定。

    Directives for the Export-Package header:

    (1)exclude : Specifies a list of packages that must be invisible to the component importing the

         package.
    (2)include : Specifies a list of packages that must be visible to the component importing the

         package.
    (3)mandatory Specifies a list of mandatory properties that must be specified when using the

        exported package in other components.
    (4)uses : Specifies a list of packages that an exported package uses. This directive is used by 

        the dependency resolver to ensure that imported package versions correspond to those
        specified here.

    默认情况下,在Export Package是,OSGi框架会自动将ExportBundles的bundle-symbolic-name和Bundle

    -Version属性添加上。

    例如:Export-Package:
             org.springframework.beans.factory.serviceloader;
             uses:="org.springframework.util,
             org.springframework.beans. factory.config,
             org.springframework.beans.factory";
             version=2.5.5, 
             org.springframework.beans.annotation;
             uses:="org.springframework.util,
             org.springframework.beans";
             version=2.5.5,

             ...

2. The header:Import-Package and It's stand attributes

    Standard attributes usable with the Import-Package header:

    (1)version : Specifies the version range for matching exported packages. If this attribute
        isn’t specified, the default value is [0.0.0, ∞). 
    (2)bundle-symbolic-name : Specifies the symbolic name of the component that exports the

        packages. In the case of a fragment bundle, the name will correspond to the host bundle’s

        symbolic name instead. A fragment is a special bundle that allows extending an existing

        bundle.

    (3)bundle-version : Specifies the version of the component that exports the packages. As
        with version, the default value is [0.0.0, ∞) and the fragment behavior is as for bundle-

        symbolic-name.

    例如:

    Import-Package: javax.el;version="[2.1.0, 3.0.0)";resolution:=optional
    net.sf.cglib.proxy;version="[2.1.3, 2.2.0)";resolution:=optional,
    org.apache.commons.logging;version="[1.0.4, 2.0.0)",
    org.springframework.core;version="[2.5.6, 2.5.6]";resolution:=optional,
    org.springframework.core.annotation;version="[2.5.6, 2.5.6]";
    resolution:=optional

 

    In addition to the previous attribute, the resolution directive of the Import-Package header

    makes it possible to change the behavior of this resolution mechanism.The first possible value

    of the directive is mandatory, which is also the default.When a package is marked as

    mandatory, it means that if the package can’t be resolved, the component itself can’t be

    resolved. The other value is optional. In this case, if the package isn’t present during the

    resolution phase, the package isn’t considered imported by the component.

3. The header: DynamicImport-Package

    It bypass the regular class-resolution mechanism we have described and instead allows

    classes to be loaded on demand at runtime. Dependencies specified in this way are ignored

    during the transition between the installed and resolved states.

 

    The DynamicImport-Package header can contain a list of packages, but it also supports two 

    wildcards for specifying package names. Moreover, these imports are searched for in the order

    in which they are specified. This ordering is important, especially when using wildcards,

    because it determines the order in which matching occurs. In the following snippet, packages

    with the value test for the attribute myattribute will be preferred over other packages.

 

    DynamicImport-Package: *;myattribute=test, *

    
    No directives are defined for this header, but the standard version, bundlesymbolic-name,  

    and bundle-version attributes can all be used for package matching with the same semantics

    as Import-Package.

4. The header: Require-Bundle

    The Require-Bundle header is provided by the OSGi specification so you can consume all

    exported packages from other components based on component symbolic names.

    The Require-Bundle only has one attribute:bundle-version,the bundle-version attribute uses

    the same semantics as the version attribute of the Import-Package header and specifies
    the component version of the dependency.

    例如:

    Manifest-Version: 1.0
    (...)
    Import-Package: javax.servlet;version="2.5.0",
    javax.servlet.http;version="2.5.0",
    javax.servlet.jsp;version="2.0.0",
    (...)
    Require-Bundle: com.springsource.javax.servlet.jsp.jstl;
    bundle-version=1.1.2,com.springsource.org.apache.taglibs.standard;
    bundle-version=1.1.2

    注意:同一份MANIFEST.MF配置文件中,Import-Package header takes priority over the Require

    -Bundle header.

 

    Directives usable with the Require-Bundle header:

    (1)visibility : When set to private (the default value), the exported packages of the

    corresponding bundles aren’t re-exported. Setting this to reexport will achieve the opposite.
    (2)resolution : Controls dependency resolution. If set to mandatory (the default value), the
    dependency must be successfully resolved for the bundle to resolve. With the optional value,

    dependencies are only resolved if they’re present, and the bundle will resolve regardless.

5. Split packages

    You saw that referencing bundles with the Require-Bundle header is equivalent to importing

    all of their exported packages. A problematic case occurs when two different required bundles 

    export the same package. Such packages are named split packages because their content

    comes from several bundles.
    Although OSGi allows split packages, you’ll notice that they have several obvious drawbacks.
    When different bundles provide the same classes, unpredictable shadowing of classes can arise.

6. Matching and Versioning

6.1 Version Matching

    The different parts of a version value:

    (1)Major number : For major updates with no provision for compatibility with previous major     

         versions.
    (2)Minor number : For functional updates compatible with the current major version (compatible

        for clients using an interface, but not for implementers).
    (3)Micro number : For bug fixes.
    (4)Qualifier : Values like “–SNAPSHOT” for the current development version can also be added

        at the end of the value. The version number with a qualifier is lower than the number without.

6.2 Optional Depedencies

    OSGi supports optional dependencies on both packages and bundles with the Import-Package

    and Require-Bundle headers.

6.3 Attribute Matching

    模式:

    Header-Name: header-value1;directive-name1:=directive-value1;attribute-name1= attribute

    -value1;attribute-name2=attribute-value2, 
    (...)

    例如:

    Export-Package: com.manning.osgi.simple;criteria="Manning";mandatory:="criteria"

    Import-Package: com.manning.osgi.simple;criteria="Manning"

目录
相关文章
|
Java 数据库连接 应用服务中间件
【Maven】依赖范围、依赖传递、依赖排除、依赖原则、依赖继承
在Maven中,依赖范围(Dependency Scope)用于控制依赖项在编译、测试和运行时的可见性和可用性。通过指定适当的依赖范围,可以在不同的构建和执行环境中控制依赖项的加载和使用。
589 1
|
3月前
|
JavaScript
Vue3相关组件项目依赖依赖版本信息
这篇文章展示了一个Vue 3项目中使用的组件和库的依赖版本信息,包括`ant-design-vue`、`swiper`、`vue`、`vue-router`等,以及开发依赖如`vite`、`vue-tsc`、`eslint`等。
Vue3相关组件项目依赖依赖版本信息
|
3月前
|
数据管理 测试技术 持续交付
组件和依赖管理
组件和依赖管理
50 0
依赖倒转与里氏替换
依赖倒转与里氏替换
64 0
依赖倒转与里氏替换
|
6月前
|
Java Maven
maven子模块无法继承父模块的jar包解决方案
maven子模块无法继承父模块的jar包解决方案
CTK框架 - 插件依赖关系 - 给插件加上界面
在第一篇文章中吗,我们提到了MANIFEST.MF中有个字段是依赖关系,这次我们来测试一下这个依赖关系:
185 0
|
存储 前端开发 Java
【Maven项目】在项目开发中对于NAPSHOT、Maven依赖关系管理以及三个标准生命周期
【Maven项目】在项目开发中对于NAPSHOT、Maven依赖关系管理以及三个标准生命周期
138 0
|
前端开发 Java Maven
常用依赖简单汇总
常用依赖简单汇总
487 0
常用依赖
1. 实现数字滚动 动态效果2. 时间转换3.深拷贝
105 0
|
Java Spring
Spring框架的jar依赖关系
Spring框架的jar依赖关系
209 0
Spring框架的jar依赖关系