首页 > 代码库 > Integrate non-OSGi Dependencies
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:
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.
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.
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/
- 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.
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。