Integrate non-OSGi Dependencies
Consider a scenario where you need to use a non-OSGi jar in your OSGi project. Most libraries are not OSGi bundles and we should repackage all them with OGSi headers to be loaded into the OSGi container. There are several ways to help you with these non-OSGi dependencies:
- Embed these jar files into your OSGi bundle
- Wrap these jar files within one OSGi bundle
For instance, you need to utilize fastjson library to serialize/deserialize json object in your OSGi bundle.
Embed these jar files into your OSGi bundle
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>com.example.demo.Activator</Bundle-Activator>
<Export-Package>
com.example.demo*;version=${project.version}
</Export-Package>
<Import-Package>
!org.springframework.*,
*
</Import-Package>
<Embed-Dependency>fastjson;scope=compile|runtime|system;inline=true</Embed-Dependency>
</instructions>
</configuration>
</plugin>
If you want a dependency inlined instead of embedded add the inline=true.
| inline=true | |
![]() |
![]() |
Wrap these jar files within one OSGi bundle
Karaf supports the wrap:protocol execution, so it allows for directly deploying third party dependencies into OSGi container:
install -s wrap:mvn:com.alibaba/fastjson/1.1.37
You can also create a wrap bundle for a third party dependency. This bundle is simply a Maven POM that shades an existing jar and package into a jar bundle.
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Import-Package>!org.springframework.*,*</Import-Package>
<Private-Package>!*</Private-Package>
<Embed-Dependency>*;scope=compile;type=!pom;inline=true</Embed-Dependency>
<Export-Package>com.alibaba.fastjson*</Export-Package>
</instructions>
</configuration>
</plugin>
References
http://karaf.apache.org/manual/latest-2.3.x/developers-guide/creating-bundles.html
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
http://baptiste-wicht.com/posts/2010/03/bundle-non-osgi-dependencies-maven.html
http://maksim.sorokin.dk/it/2011/08/09/maven-apache-felix-strategy-to-handle-non-osgi-dependencies/
Integrate non-OSGi Dependencies的更多相关文章
- Liferay7 BPM门户开发之38: OSGi模块化Bndtools、Maven、Gradle开发构建入门
前言 OSGi是目前动态模块系统的事实上的工业标准,它适用于任何需要模块化.面向服务.面向组件的应用程序.Eclipse如此庞大和复杂的插件体系,就是基于OSGi.Liferay也是基于OSGi.OS ...
- maven-bundle-plugin插件, 用maven构建基于osgi的web应用
maven-bundle-plugin 2.4.0以下版本导出META-INF中的内容到MANIFEST.MF中 今天终于把maven-bundle-plugin不能导出META-INF中的内容到Ex ...
- osgi实战学习之路:3. osgi分层概念及相互合作demo
源码下载 分层: modual: 主要作用于包级管理与共享代码 lifecycle: 主要作用于执行期间的模块管理与訪问osgi底层框架 service: 主要作用于多模块之间的相互通信 demo: ...
- OSGI企业应用开发(九)整合Spring和Mybatis框架(二)
上篇文章中,我们完成了在OSGI应用中整合Spring和Mybatis框架的准备工作,本节我们继续Spring和Mybatis框架的整合. 一.解决OSGI整合Spring中的Placeholder问 ...
- OSGI企业应用开发(七)细说Blueprint & Gemini Blueprint(二)
上篇文章介绍了标准的Blueprint 规范与 Gemini Blueprint如何自定义Bean配置文件路径,本文接着上篇文章继续介绍Blueprint的使用. 一.Bean的配置 前面提到过,Ge ...
- OSGI企业应用开发(六)细说Blueprint & Gemini Blueprint(一)
上篇文章介绍了如何使用Blueprint將Spring框架整合到OSGI应用的Bundle中,从上篇文章中我们大概了解了Blueprint与Gemini Blueprint的关系,简单的说,Bluep ...
- OSGI企业应用开发(五)使用Blueprint整合Spring框架(二)
上篇文章中,我们开发了一个自定义的Bundle,接着从网络中下载到Spring和Blueprint的Bundle,然后复制到DynamicRuntime项目下. 需要注意的是,这些Bundle并不能在 ...
- OSGI企业应用开发(四)使用Blueprint整合Spring框架(一)
上篇文章中介绍了如何使用独立的Equinox发行包搭建OSGI运行环境,而不是依赖与具体的Eclipse基础开发工具,本文开始介绍如何使用Blueprint將Spring框架整合到OSGI中. 一.开 ...
- OSGI企业应用开发(二)Eclipse中搭建Felix运行环境
上篇文章介绍了什么是OSGI以及使用OSGI构建应用的优点,接着介绍了两款常用的OSGI实现,分别为Apache Felix和Equinox,接下来开始介绍如何在Eclipse中使用Apache Fe ...
随机推荐
- centos 6.5 msyql5.6安装
MySQL 安装 安装mysql前需要查询系统中含有的有关mysql的软件. rpm -qa | grep -i mysql 如下 代表有mysql ,则先进行卸载 mysql-libs-5.1. ...
- Ruby-模块和类
首先看下他们的关系 irb(main):100:0> String.class => Class irb(main):101:0> String.class.superclass ...
- ROW_NUMBER over (order by **)
ROW_NUMBER必须指写over (order by **),有时我根本就不想排序,想按原始顺序 )) AS ROWNUM,* FROM t
- Altium Designer PCB双面板制作打印操作步骤
Altium Designer PCB双面板制作打印操作步骤百度知道:http://jingyan.baidu.com/article/335530da83441c19cb41c3db.html?st ...
- 如何得到EF(ADO.NET Entity Framework)查询生成的SQL? ToTraceString Database.Log
ADO.NET Entity Framework ToTraceString //输出单条查询 DbContext.Database.Log //这里有详细的日志
- 使用NPOI2.1.3.1版本导出word附带表格和图片
原文:http://www.cnblogs.com/afutureBoss/p/4074397.html?utm_source=tuicool&utm_medium=referral 最近项目 ...
- websocket实例(显示文件导入处理进度)
大批量数据导入时,需要即时显示对文件的处理进度.考虑ajax轮询太浪费资源,使用websocket实现. 项目使用Spring MVC(3.1),与websocket结合要求版本4.0以上.所以没有使 ...
- laravel中日志为daily时如何设置最大保存天数
在laravel中,日志设置为daily时,默认保存七天的日志,超过则清除七天前的日志.可修改默认的设置,假如要保存30天的日志,则配置如下: 在配置文件config/app.php中添加如下代码: ...
- sql server 执行计划(execution plan)介绍
大纲:目的介绍sql server 中执行计划的大致使用,当遇到查询性能瓶颈时,可以发挥用处,而且带有比较详细的学习文档和计划,阅读者可以按照我计划进行,从而达到对执行计划一个比较系统的学习. 什么是 ...
- 用 python实现简单EXCEL数据统计
任务: 用python时间简单的统计任务-统计男性和女性分别有多少人. 用到的物料:xlrd 它的作用-读取excel表数据 代码: import xlrd workbook = xlrd.open_ ...

