usm*_*man 3 java packaging maven apache-karaf karaf
我有各种自制项目,具有第三方库依赖项.我将它们捆绑为OSGI容器但无法解决我的项目中的深度依赖项.现在我正在寻找karaf文件夹,我可以放置我的库,所以捆绑可以直接访问它们而不是安装它们.
更多我正在使用maven.
编辑:在遵循你的'功能'解决方案后,我能够产生明显的传递依赖性,但问题是现在它也寻找非常常见的java文件:例如:下面是相当大的依赖列表:
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
Run Code Online (Sandbox Code Playgroud)
回答你的问题:你可以将所有依赖包都删除到$ KARAF_HOME/deploy文件夹中,然后Karaf会为你部署它们.
但是,这不是很方便,因为它是一个手动过程而不是由Maven驱动.而是看看Karaf的功能存储库概念.您可以使用Karaf maven插件为捆绑包及其(传递)依赖项创建功能存储库.如果需要将应用程序作为单个工件发送,则可以使用相同的插件创建KAR存档,该存档是一个zip文件,其中包含功能存储库和自包含部署单元中所需的依赖项.
要开始,请将模板feature.xml文件放入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>
Run Code Online (Sandbox Code Playgroud)
然后设置插件以根据您的maven依赖项填充功能模板:
<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>
Run Code Online (Sandbox Code Playgroud)
构建项目将在本地maven存储库中与您的bundle jar一起创建一个额外的maven工件:xxx-features.xml您可以使用该feature:repo-add命令使本地Karaf知道您的功能存储库.然后使用该feature:install命令添加您的功能.这将启动您的bundle及其所有声明的(传递的)Maven依赖项.
编辑:
当你在评论中提到,在某些(所有?)你的依赖是普通JAR文件,而不是OSGi包,可能是你最好嵌入这些非OSGi的依赖到你自己的捆绑使用Maven束的插件.但这可能非常繁琐.大多数非OSGi JAR都具有在运行时根本不使用的包导入,或者在特定使用方案中未使用的包导入.要避免吹起来的OSGi的依赖列表超出你传递Maven依赖的名单,你就必须防止这些"继承"包被添加到包进口清单在自己的包的清单.例如,我有一个使用httl模板库的bundle,它再次依赖于Javassist.OSGi捆绑包也不是.所以我嵌入了两个并禁止导入在httl或javassist代码中声明但在运行时不需要的包:
<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>
Run Code Online (Sandbox Code Playgroud)