简体   繁体   English

如何使用maven项目轻松部署到Karaf Osgi容器

[英]How to deploy easily to Karaf Osgi container with maven project

I'm developing an OSGI bundle for parsing a PDF file using PDFBox library. 我正在开发一个OSGI包,用于使用PDFBox库解析PDF文件。 I use maven to build the project and Karaf as the OSGI container. 我使用maven构建项目,使用Karaf作为OSGI容器。 The PDFBox library is OSGI compatible so I thought this would be easy. PDFBox库与OSGI兼容,所以我认为这很容易。 But I just can't get the deployment model right. 但我无法正确获得部署模型。

In a traditional web app I would build a single WAR-file containing all the dependencies and put it in a Servlet container and it would get deployed. 在传统的Web应用程序中,我将构建一个包含所有依赖项的WAR文件,并将其放在Servlet容器中,然后部署它。 On the other hand the only way I've figured how to install an osgi bundle is by doing it by hand. 另一方面,我想出如何安装osgi包的唯一方法是手工完成。 I have to create an installation instruction file that lists all the dependencies that have to be manually downloaded and copied to the Karaf deploy folder, and be sure to do it in the right order. 我必须创建一个安装指令文件,列出必须手动下载并复制到Karaf部署文件夹的所有依赖项,并确保按正确的顺序执行。 I feel like I'm back in the stone ages. 我觉得自己又回到了石器时代。

There has got to be an easier way, right? 必须有一个更简单的方法,对吧? I still use maven to declare dependencies but I just have to use the provided scope. 我仍然使用maven来声明依赖项,但我只需要使用提供的范围。 It would be great if those dependencies could be automatically installed. 如果可以自动安装这些依赖项,那将会很棒。

I'm using the maven-bundle-plugin to generate a bundle from my application. 我正在使用maven-bundle-plugin从我的应用程序生成一个包。 It does generate an OBR repository(repository.xml) and I tried installing my bundle using obr karaf plugin but it still doesn't help with dependencies. 它确实生成了一个OBR存储库(repository.xml),我尝试使用obr karaf插件安装我的软件包,但它仍然无法帮助依赖。

There are different possibilities for provisioning bundles. 配置捆绑包有不同的可能性。 I prefer to install a bundle using Maven via the Karaf console such as: 我更喜欢通过Karaf控制台使用Maven安装捆绑包,例如:

install mvn:org.apache.pdfbox/pdfbox/1.8.4

If you don't want to install every bundle one by one, you could use so called features as described here . 如果您不想逐个安装每个捆绑包,则可以使用此处所述的所谓功能 A feature lists all needed bundles: 功能列出了所有需要的包:

<feature name='my-project' version='1.0.0'>
    <feature version='2.4.0'>camel-spring</feature>
    <bundle start-level='80' start='false'>mvn:com.mycompany.myproject/myproject-dao</bundle>    
    <bundle start-level='85' start='false'>mvn:com.mycompany.myproject/myproject-service</bundle>
    <bundle start-level='85' start='false'>mvn:com.mycompany.myproject/myproject-camel-routing</bundle>
</feature> 

You add a feature via Karaf console: 您通过Karaf控制台添加功能:

features:addUrl mvn:org.apache.servicemix.nmr/apache-servicemix-nmr/1.0.0-m2/xml/features
features:install nmr

Instead of the mvn handler, you could also use the file handler: 您也可以使用file处理程序代替mvn处理程序:

features:addUrl file:base/features/features.xml

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

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