问题描述
我有各种具有第三方库依赖项的自制项目.我正在为 OSGI 容器捆绑它们,但无法解决我的项目中的深层依赖关系.现在我正在寻找 karaf 文件夹,我可以在其中放置我的库,以便捆绑包可以直接访问它们而不是安装它们.
I have various self made projects that have third party libraries dependencies.I am bundling them for OSGI container but unable to resolve deep dependencies in my projects.Now i am looking for karaf folder where i can place my libraries so bundles can directly access them and not to install them.
我也在使用 maven.
More over i am using maven too.
遵循您的功能"解决方案后,我能够生成包含传递依赖项的清单,但现在问题是它还会查找非常常见的 Java 文件:例如:下面是相当大的依赖项列表:
After following your 'feature' solution i am able to produce manifest containg transitive dependencies but problem is now it also look for very common java files: e.g: below is list of quite big dependencies:
bsh -- Cannot be resolved
com.fasterxml.jackson.annotation -- Cannot be resolved
com.fasterxml.jackson.core -- Cannot be resolved
com.fasterxml.jackson.databind -- Cannot be resolved
com.fasterxml.jackson.databind.annotation -- Cannot be resolved
com.fasterxml.jackson.databind.module -- Cannot be resolved
com.gargoylesoftware.htmlunit -- Cannot be resolved
com.gargoylesoftware.htmlunit.util -- Cannot be resolved
com.google.protobuf -- Cannot be resolved
com.ibm.uvm.tools -- Cannot be resolved
com.ibm.websphere.uow -- Cannot be resolved
com.ibm.wsspi.uow -- Cannot be resolved
com.jamonapi -- Cannot be resolved
com.jamonapi.utils -- Cannot be resolved
com.jayway.jsonpath -- Cannot be resolved
com.jcraft.jzlib -- Cannot be resolved
com.mysema.query.types -- Cannot be resolved
com.sun.javadoc -- Cannot be resolved and overwritten by Boot Delegation
com.sun.jdmk.comm -- Cannot be resolved and overwritten by Boot Delegation
com.sun.net.httpserver -- Cannot be resolved and overwritten by Boot Delegation
com.sun.tools.javadoc -- Cannot be resolved and overwritten by Boot Delegation
com.sun.xml.fastinfoset.sax -- Cannot be resolved and overwritten by Boot Delegation
com.sun.xml.fastinfoset.stax -- Cannot be resolved and overwritten by Boot Delegation
com.typesafe.config -- Cannot be resolved
groovy.lang -- Cannot be resolved
groovy.xml -- Cannot be resolved
javassist -- Cannot be resolved
javax.activation from org.apache.felix.framework (0)
javax.annotation from org.apache.felix.framework (0)
javax.crypto from org.apache.felix.framework (0)
javax.crypto.spec from org.apache.felix.framework (0)
javax.ejb -- Cannot be resolved
javax.el -- Cannot be resolved
javax.enterprise.concurrent -- Cannot be resolved
javax.enterprise.context -- Cannot be resolved
javax.enterprise.context.spi -- Cannot be resolved
javax.enterprise.event -- Cannot be resolved
javax.enterprise.inject -- Cannot be resolved
javax.enterprise.inject.spi -- Cannot be resolved
javax.enterprise.util -- Cannot be resolved
推荐答案
回答您的问题:您可以将所有依赖包放到 $KARAF_HOME/deploy 文件夹中,Karaf 将为您部署它们.
To answer your question: You could drop all your dependency bundles into the $KARAF_HOME/deploy folder and Karaf would deploy them for you.
然而,这不是很方便,因为它是一个手动过程,不是由 Maven 驱动的.相反,请查看 Karaf 的功能存储库 的概念.您可以使用 Karaf maven 插件 为您的包及其包创建功能存储库(传递)依赖.如果您需要将您的应用程序作为单个工件发布,您可以使用相同的插件创建一个 KAR 存档,该存档是一个 zip 文件,在一个独立的部署单元中包含功能存储库和所需的依赖项.
However, this is not very convenient as it is a manual process and not driven by Maven. Instead have a look at Karaf's concept of feature repositories. You can use the Karaf maven plugin to create a feature repository for your bundles and their (transitive) dependencies. If you need to ship your application as a single artifact, you can use the same plugin to create a KAR archive, which is zip file that contains both the feature repository and the required dependencies in a self-contained deployment unit.
首先将模板 feature.xml 文件放入 src/main/feature
:
To get started put a template feature.xml file into src/main/feature
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.3.0 http://karaf.apache.org/xmlns/features/v1.3.0"
name="My feature">
<feature name="${project.artifactId}" version="${project.version}" description="Describe feature here">
<!-- Add "self" to the list of dependencies -->
<bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle>
</feature>
</features>
然后设置插件以根据您的 maven 依赖项填充功能模板:
Then set up the plugin to populate the feature template based on your maven dependencies:
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<configuration>
<includeTransitiveDependency>true</includeTransitiveDependency>
</configuration>
<executions>
<execution>
<id>generate-features-descriptor</id>
<goals>
<goal>features-generate-descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
构建您的项目将在您的本地 maven 存储库中创建一个额外的 maven 工件以及您的包 jar:xxx-features.xml您可以使用 feature:repo-add
命令让本地 Karaf 了解您的功能存储库.然后使用 feature:install
命令添加您的功能.这将启动您的包及其所有声明的(可传递的)Maven 依赖项.
Building your project will create an additional maven artifact together with your bundle jar in your local maven repository: xxx-features.xmlYou can make a local Karaf aware of your feature repository with the feature:repo-add
command. Then add your feature with the feature:install
command. This will start your bundle and all its declared (transitive) Maven dependencies.
正如您在评论中提到的,您的某些(全部?)依赖项是普通的 JAR,而不是 OSGi 包,可能您最好使用 将那些非 OSGi 依赖项嵌入 使用 maven-bundle-plugin 将这些非 OSGi 依赖项嵌入到您自己的包中.不过,这可能非常乏味.大多数非 OSGi JAR 都有包导入,它们要么在运行时根本不使用,要么在您的特定使用场景中不使用.为了避免将你的 OSGi 依赖列表炸毁到你的可传递 maven 依赖列表之外,你必须阻止那些继承的"依赖列表.包不会被添加到您自己的包的清单中的包导入列表中.例如,我有一个使用 httl 模板库的包,它再次依赖于 Javassist.OSGi 包也不是.因此,我将两者都嵌入并禁止导入在 httl 或 javassist 代码中声明但在运行时不需要的包:
As you mentioned in the comments that some (all?) your dependencies are plain JARs, not OSGi bundles, possibly you are better off embedding those non-OSGi dependencies into your own bundle with the maven-bundle-plugin. This can be quite tedious though. Most non-OSGi JARs have package imports that are either not used during runtime at all, or not used in your specific usage scenario. To avoid blowing up your OSGi dependency list beyond your list of transitive maven dependencies, you then have to prevent those "inherited" packages from being added to the list of package imports in the MANIFEST of your own bundle. E.g., I have a bundle that uses the httl template library, which again depends on Javassist. Neither are OSGi bundles. So I embed both and suppress the import of the packages declared in either the httl or javassist code but not required at runtime:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime;inline=false;artifactId=httl|javassist</Embed-Dependency>
<Embed-Transitive>false</Embed-Transitive>
<Import-Package>
!com.alibaba.*,
!com.thoughtworks.*,
!javassist.*,
!net.htmlparser.*,
!org.apache.commons.logging.*,
!org.codehaus.jackson.*,
!org.joda.convert.*,
!com.sun.jdi.*,
!javax.servlet.*,
*
</Import-Package>
</instructions>
</configuration>
</plugin>
这篇关于我可以将第三方 jars 放在 karaf(任何特定文件夹)中以解决传递依赖关系吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!