简体   繁体   English

OSGI Architecture和Maven多模块项目之间有什么区别?

[英]What is the difference between OSGI Architecture and Maven multi module project?

I am trying to understand OSGI, as per definition it says 我试图理解OSGI,按照它的定义

OSGi technology is a set of specifications that define a dynamic component system for Java. OSGi技术是一组规范,这些规范定义了Java的动态组件系统。 These specifications enable a development model where an application is composed of several components which are packaged in bundles. 这些规范实现了一个开发模型,其中应用程序由打包成捆的几个组件组成。 Components communicate locally and across the network through services. 组件通过服务在本地和整个网络之间进行通信。

But I am confused here as the same dynamic module creation can be done with Maven multi module project structure too. 但是我在这里感到困惑,因为同样的动态模块创建也可以使用Maven多模块项目结构来完成。 So my question is how OSGI architecture is different from Maven multi module projects. 所以我的问题是OSGI架构与Maven多模块项目有何不同。

The main difference between maven and OSGi is how modules depend on each other. maven和OSGi之间的主要区别在于模块之间如何相互依赖。

In maven a module depends on a list of other maven modules. 在Maven中,一个模块取决于其他Maven模块的列表。 This is a simple model but often leads into problems in transitive dependencies. 这是一个简单的模型,但通常会导致传递依存关系方面的问题。 If the same module appears in the dependency tree with different versions maven simply chooses the highest version. 如果相同的模块出现在具有不同版本的依赖关系树中,则maven只会选择最高版本。 This is a good guess but does not always work. 这是一个很好的猜测,但并不总是有效。 Another typical case is having two modules with the same packages but different names (split packages). 另一个典型的情况是,两个模块具有相同的程序包,但名称不同(分离的程序包)。

In OSGi dependencies are expressed as requirements and capabilities. 在OSGi中,依赖性表示为需求和功能。 The OSGi resolver is then used at assembly time of your application to find a closure over the candidate bundles (repository) that satisfy a set of initial requirements. 然后,在应用程序组装时使用OSGi解析器在满足一组初始要求的候选包(存储库)上查找闭包。 Most commonly these initial reuirements are your top level user bundles. 这些初始需求最常见的是您的顶级用户捆绑包。 The resolver then determines a closure over the bundles that solves the requiremnts. 然后,解析程序确定对束的闭合以解决需求。 So the obvious advantage is that when using the resolver you have a high confidence that the set of bundles you run will actually work. 因此,明显的优势在于,在使用解析器时,您可以高度确信您运行的捆绑包确实可以工作。 In plain java you simply run some jars together and hope for the best. 在纯Java中,您只需一起运行一些jar并希望获得最佳效果。

The most common requirement is on a package in a version range. 最常见的要求是版本范围内的软件包。 Another bundle may offer the package in a suitable version. 另一个捆绑包可能会提供合适版本的包装。 It is then a candidate for the resolver. 然后,它是解析器的候选者。

Luckily at build time creating bundles from maven builds is easy. 幸运的是,在构建时,从Maven构建中创建捆绑包很容易。 You use the bnd-maven-plugin or maven-bundle-plugin. 您可以使用bnd-maven-plugin或maven-bundle-plugin。 It typically figures out the requirements and capabilities on its own. 它通常自行计算出需求和功能。

In OSGi you always try to develop against APIs (API-jars) instead of runtime jars. 在OSGi中,您总是尝试针对API(API罐)而不是运行时jar进行开发。 This makes your code more loosely coupled. 这使您的代码更加松散地耦合在一起。

At assembly time in OSGi you need to provide a set of bundles to form the repository for the resolver to work on. 在OSGi中进行组装时,您需要提供一组捆绑软件以形成用于解析程序的存储库。 This is often done using a pom. 这通常是使用pom完成的。 So actually this is not too different from plain maven. 因此,实际上这与普通行家并没有太大区别。 The main difference is that the resolver gives you a validates minimal set of bundles to run while a typical mavne build simply gives you a set of jars that represent all transitive dependencies. 主要区别在于,解析程序为您提供了一组可运行的验证包,而典型的mavne构建只是为您提供了一组代表所有传递依赖项的jar。

As an example see the new enroute microservice example . 例如,请参见新的途中微服务示例 It shows how to create the individual bundles and how to assemble them into a running application. 它显示了如何创建单个捆绑包以及如何将它们组装到正在运行的应用程序中。 See also the tutorial for the example . 有关示例,另请参见教程

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

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