本文介绍了如何部署OSGi应用程序和依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过不将数十个JAR依赖项包装到lib目录中,OSGi似乎具有很小的可部署工件的优点。但是,我找不到任何能告诉我将依赖项部署到容器的简单可靠方法。例如,我有一个使用CXF和几个Spring子项目的应用程序。如果我需要将此应用程序部署到新的Glassfish服务器,那么最好的方法是什么,确保安装所有依赖项?



我正在使用Maven,而似乎可能有某种方法可以有一个查看META-INF /的钩子maven目录并从pom.xml中提取依赖项列表,并获取所需的库(可能来自本地存储库)。有没有办法做到这一点?



Pax插件听起来像是在做这个,但它似乎是基于提升Felix容器?这不是我想要的,我正在处理已经运行的远程容器。



有没有像命令行工具那样存在镜头而不是GUI?

解决方案

有许多方法可以将依赖包部署到OSGi容器。以下是其中一些:



1 Felix OBR捆绑存储库



首先需要创建XML索引使用bindex等工具为您的可用包提供文件。如果您正在使用maven-bundle-plugin,那么它会自动在〜/ .m2 / repository / repository.xml中维护一个OBR索引。



使用OBR命令行界面:

 > obr:addUrl文件:/Users/derek/.m2/repository/repository.xml 

然后询问OBR部署目标捆绑包,依赖于OBR索引:

 > obr:deploy com.paremus.posh.sshd 
目标资源:
-------------------
Paremus Posh Ssh守护进程(1.0.23.SNAPSHOT)

所需资源:
---------------------
Paremus Command API(1.0.23.SNAPSHOT)

可选资源:
---------------------
Paremus配置管理命令(1.0.23.SNAPSHOT)
Paremus OSGi& LDAP类型(1.0.23.SNAPSHOT)



2 Apache Karaf



Karaf支持功能,基本上是提供功能所需的捆绑包列表:

  karaf @根>功能:info obr 
obr 2.0.0功能描述
------------------------------- ---------------------------------
功能没有配置
功能没有依赖项。
功能包含以下捆绑包:
mvn:org.apache.felix / org.apache.felix.bundlerepository / 1.6.4
mvn:org.apache.karaf.shell/org.apache。 karaf.shell.obr / 2.0.0
mvn:org.apache.karaf.features / org.apache.karaf.features.obr / 2.0.0

karaf @ root>功能:安装obr



3 Eclipse Virgo



Virgo使用计划来定义构成应用程序的工件,它能够
自动提供应用程序的依赖项,包括包,计划,计划存档(PAR)和配置,本地和远程存储库。



4 Paremus Nimble



Nimble使用OBR(或其自己的扩展)存储库索引,自动部署激活目标软件包所需的所有依赖软件包(并在目标软件包停止时卸载它们)。它还可以检测其他依赖项,例如WAB包需要Web扩展程序并根据可配置的策略自动安装。



Nimble也可以配置为启动Glassfish ,以便它的功能可用于Glassfish容器中的捆绑包。



下面的示例还显示在激活sshd时自动安装日志记录支持:

  $ posh 
________________________________________
欢迎来到Paremus Nimble!
输入帮助以获取帮助。
[denzil.0]%nim:add --dry-run com.paremus.posh.sshd@active
- 要安装的已分类部件 -
4325 osgi.resolved.bundle / ch.qos.logback.core:0.9.22
- 启动依赖循环 -
5729 osgi.resolved.bundle / com.paremus.util.logman:1.0.23.SNAPSHOT
5727 osgi.active.bundle / com.paremus.util.logman:1.0.23.SNAPSHOT
3797 osgi.resolved.bundle / ch.qos.logback.classic:0.9.25.SNAPSHOT
3792 osgi .resolved.bundle / slf4j.api:1.6
- 结束依赖循环 -
436 osgi.resolved.bundle / org.apache.mina.core:2.0.0.RC1
6533 osgi.resolved.bundle / sshd-core:0.3
398 osgi.resolved.bundle / com.paremus.posh.sshd:1.0.23.SNAPSHOT
396 osgi.active.bundle / com.paremus。 posh.sshd:1.0.23.SNAPSHOT

(免责声明:我是Paremus的开发人员)



5 Apache Felix Gogo



gogo是新的RFC147标准命令行shell。它已经在Felix,Karaf,Nimble中使用,很快将在Glassfish中使用。



Gogo允许您以脚本的形式运行任何可以交互式输入的命令。因此,您可以生成要安装的软件包列表并将其转换为脚本,甚至从工作配置中捕获已安装的软件包,以便可以从干净的开始重新创建它。


OSGi seems to have an excellent benefit of having small deployable artifacts by not wrapping dozens of JAR dependencies into a lib directory. However, I can't find anything that tells me an easy, reliable way to deploy dependencies to a container. For instance, I have an application that uses CXF and several Spring subprojects. If I need to deploy this application to a new Glassfish server, what would be the best way to do so, ensuring that all dependencies get installed?

I'm using Maven, and it would seem that there could be some way to have a hook that looks at the META-INF/maven directory and pulls the dependency list from the pom.xml and goes and fetches the required libs (probably from a local repo). Is there a way to do that?

The Pax plugin sort of sounds like it's doing this, but it seems to be based around boostrapping a Felix container? Which is not what I want, I am dealing with an already running, remote container.

Is there any shot such a thing exists as command line tool as opposed to GUI as well?

解决方案

There are a number of ways to deploy dependent bundles to OSGi containers. Here are some of them:

1 The Felix OBR bundle repository

You first need to create an XML index file for your available bundles, using a tool such as bindex. If you are using the maven-bundle-plugin, then it automatically maintains an OBR index in ~/.m2/repository/repository.xml.

Load the index using the OBR command-line interface:

> obr:addUrl file:/Users/derek/.m2/repository/repository.xml

Then ask OBR to deploy your target bundle, with dependencies determined from the OBR index:

> obr:deploy com.paremus.posh.sshd
Target resource(s):
-------------------
   Paremus Posh Ssh Daemon (1.0.23.SNAPSHOT)

Required resource(s):
---------------------
   Paremus Command API (1.0.23.SNAPSHOT)

Optional resource(s):
---------------------
   Paremus Config Admin Commands (1.0.23.SNAPSHOT)
   Paremus OSGi & LDAP Types (1.0.23.SNAPSHOT)

2 Apache Karaf

Karaf supports "features", which are basically lists of bundles required to provide the feature:

karaf@root> features:info obr
Description of obr 2.0.0 feature
----------------------------------------------------------------
Feature has no configuration
Feature has no dependencies.
Feature contains followed bundles:
  mvn:org.apache.felix/org.apache.felix.bundlerepository/1.6.4
  mvn:org.apache.karaf.shell/org.apache.karaf.shell.obr/2.0.0
  mvn:org.apache.karaf.features/org.apache.karaf.features.obr/2.0.0

karaf@root> features:install obr

3 Eclipse Virgo

Virgo uses plans to define the artifacts that comprise an application and it is able toautomatically supply the dependencies of an application including bundles, plans, plan archives (PARs), and configurations, from both local and remote repositories.

4 Paremus Nimble

Nimble uses OBR (or its own extended) repository indexes, to automatically deploy all dependent bundles needed to activate a target bundle (and uninstalls them when the target bundle is stopped). It can also detect other dependencies, such as a WAB bundle requires a web-extender and automatically install one according to a configurable policy.

Nimble can also be configured to launch Glassfish, so that its features are available to bundles in the Glassfish container.

The example below also shows that logging support is automatically installed when sshd is activated:

$ posh
________________________________________
Welcome to Paremus Nimble!
Type 'help' for help.
[denzil.0]% nim:add --dry-run com.paremus.posh.sshd@active
-- sorted parts to install --
4325   osgi.resolved.bundle/ch.qos.logback.core:0.9.22
-- start dependency loop --
5729   osgi.resolved.bundle/com.paremus.util.logman:1.0.23.SNAPSHOT
5727   osgi.active.bundle/com.paremus.util.logman:1.0.23.SNAPSHOT
3797   osgi.resolved.bundle/ch.qos.logback.classic:0.9.25.SNAPSHOT
3792   osgi.resolved.bundle/slf4j.api:1.6
-- end dependency loop --
436   osgi.resolved.bundle/org.apache.mina.core:2.0.0.RC1
6533   osgi.resolved.bundle/sshd-core:0.3
398   osgi.resolved.bundle/com.paremus.posh.sshd:1.0.23.SNAPSHOT
396   osgi.active.bundle/com.paremus.posh.sshd:1.0.23.SNAPSHOT

(disclaimer: I'm a developer at Paremus)

5 Apache Felix Gogo

gogo is the new RFC147 standard command-line shell. It is already used in Felix, Karaf, Nimble and will soon be available in Glassfish.

Gogo allows you to run any commands that you could type interactively, as a script. So you could generate the list of bundles to install and convert it to a script, or even capture the installed bundles from a working configuration so that it can be re-created from a clean start.

这篇关于如何部署OSGi应用程序和依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:04