OSGi(Karaf)解决方案与Maven依赖关系

时间:2016-05-10 16:37:54

标签: java maven osgi apache-karaf

在下面的示例中,OSGi解析和Maven依赖支持中的所需步骤似乎存在差异/重复。

我有一个依赖于外部第三方jar的jar,在本例中是time4j。

<dependency>
  <groupId>net.time4j</groupId>
  <artifactId>time4j-core</artifactId>
  <version>4.16</version>
</dependency>

然后我可以通过导入包并运行等来在本地运行我的简单jar。

导入OSGi时,我必须首先确保导入此jar,通常使用PAX Wrap Url。

这对于1个jar依赖项是可以的,但是当存在多个依赖项时呢?我可以使用features.xml文件来收集这些罐子,但为什么呢?我已经在我的pom.xml中指定了它们。

似乎应该有一种方法让OSGi / Karaf读取pom.xml依赖项并在需要时使用PAX Wrap url将它们导入容器。

我错过了什么吗?

1 个答案:

答案 0 :(得分:4)

很抱歉,但您的期望与现实并不一致。 首先,Maven依赖项是构建时依赖项。这就是为什么你声明你知道在运行时可用的依赖项

<fo:block>
<fo:block opsc:lid="N.00012999.0001001.001">
<fo:block font-family="OpsComposer" font-size="9.5pt" widows="2" orphans="2" margin-left="3mm" opsc:lid="N.00012999.0001001.002" text-align="left">
The planner must correct the values for the fuel and the time obtained from the integrated cruise tables with the numbers given in the following tables. The tables which are established for <fo:inline keep-together.within-line="always">
M .78</fo:inline>
 and long range speed, take into account climbing from the brake release point at <fo:inline keep-together.within-line="always">
250 kt</fo:inline>
/?<fo:inline keep-together.within-line="always">
300 kt</fo:inline>
/?<fo:inline keep-together.within-line="always">
M .78</fo:inline>
.</fo:block>
</fo:block>
</fo:block>
<fo:block>
<fo:block opsc:lid="N.00012999.0019001.001" font-family="OpsComposer" font-size="9.5pt">
<fo:block space-before="5pt" space-after="5pt" keep-together.within-page="8" keep-with-next.within-page="always">
<fo:block margin-left="3mm" keep-with-next.within-page="always" font-family="OpsComposer" font-size="9.5pt" font-weight="bold" text-decoration="underline">
<fo:inline>
<fo:inline keep-together.within-line="always">
M .78</fo:inline>
 AND LONG RANGE SPEED</fo:inline>
</fo:block>
</fo:block>
</fo:block>
<fo:block opsc:lid="N.00012999.0019001.140">
<fo:block opsc:lid="N.00012999.0019001.141" space-before="5pt" space-after="5pt">
<fo:table table-layout="fixed" width="100%" hyphenate="false" border-collapse="collapse" fpc:table-omit-header-at-start="true" fpc:table-omit-footer-at-end="true">
<fo:table-column column-number="1" column-width="proportional-column-width(1)"/>
<fo:table-header start-indent="0pt" end-indent="0pt" keep-together.within-page="1">
<fo:table-row>
<fo:table-cell>
<fo:block font-family="OpsComposer" font-size="7.9pt" text-align="right" font-style="italic" font-weight="normal">
Continued from the previous page</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block/>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell border-bottom="1pt solid black">
<fo:block/>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-footer start-indent="0pt" end-indent="0pt" keep-together.within-page="1">
<fo:table-row>
<fo:table-cell>
<fo:block/>
</fo:table-cell>
</fo:table-row>
<fo:table-row>
<fo:table-cell>
<fo:block font-family="OpsComposer" font-size="7.9pt" text-align="right" font-style="italic" font-weight="normal">
Continued on the following page</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-footer>
<fo:table-body start-indent="0pt" end-indent="0pt">
<fo:table-row keep-with-next.within-page="always" keep-together.within-page="always">
<fo:table-cell/>
</fo:table-row>
<?opsc-table-header-separation 1?>
<fo:table-row>
<fo:table-cell>
<fo:table table-layout="fixed" width="100%" hyphenate="false" border-collapse="collapse" border-top="1pt solid black" border-bottom="1pt solid black" border-right="1pt solid black" border-left="1pt solid black" keep-with-next.within-page="6">
<fo:table-column column-number="1" column-width="8.229999999999999%"/>
<fo:table-column column-number="2" column-width="7.059999999999999%"/>
<fo:table-column column-number="3" column-width="7.059999999999999%"/>
<fo:table-column column-number="4" column-width="7.059999999999999%"/>
<fo:table-column column-number="5" column-width="7.059999999999999%"/>
<fo:table-column column-number="6" column-width="7.059999999999999%"/>
<fo:table-column column-number="7" column-width="7.059999999999999%"/>
<fo:table-column column-number="8" column-width="7.059999999999999%"/>
<fo:table-column column-number="9" column-width="7.059999999999999%"/>
<fo:table-column column-number="10" column-width="7.059999999999999%"/>
<fo:table-column column-number="11" column-width="7.059999999999999%"/>
<fo:table-column column-number="12" column-width="7.059999999999999%"/>
<fo:table-column column-number="13" column-width="14.109999999999998%"/>
<fo:table-header start-indent="0pt" end-indent="0pt" font-style="normal" font-weight="bold" keep-together.within-page="4" keep-with-next.within-page="5">
<fo:table-row opsc:lid="N.00012999.0019001.142" border-right="1pt solid black" border-left="1pt solid black" keep-with-next="always" keep-together.within-page="6">
<fo:table-cell padding-left="1pt" padding-right="1pt" column-number="1" number-columns-spanned="13" border-bottom="1pt solid black" text-align="center" display-align="center">
<fo:block>
<fo:block font-family="OpsComposer" font-size="8pt" widows="2" orphans="2" margin-left="0mm" opsc:lid="N.00012999.0019001.143" font-weight="bold">
 CLIMB CORRECTION ON FUEL CONSUMPTION (1000 KG) </fo:block>
</fo:block>
</fo:table-cell>
</fo:table-row>
<fo:table-row opsc:lid="N.00012999.0019001.144" border-right="1pt solid black" border-left="1pt solid black" keep-with-next="2" keep-together.within-page="1">
<fo:table-cell padding-left="1pt" padding-right="1pt" column-number="1" border-bottom="1pt solid black" border-right="1pt solid black" number-rows-spanned="2" text-align="center" display-align="center">
<fo:block>
<fo:block font-family="OpsComposer" font-size="9.5pt" font-weight="bold">
 FL </fo:block>
</fo:block>
</fo:table-cell>
<fo:table-cell padding-left="1pt" padding-right="1pt" column-number="2" number-columns-spanned="11" border-bottom="1pt solid black" border-right="1pt solid black" text-align="center" display-align="center">
<fo:block>
<fo:block font-family="OpsComposer" font-size="8.9pt">
 WEIGHT AT BRAKE RELEASE (1000 KG) </fo:block>
</fo:block>
</fo:table-cell>`

OSGi和Karaf都无法对构建时依赖性做任何事情。 使用OSGi ,您可以确保您的构建依赖项在运行时也可用,并且不会干扰可能的其他库。

这就是你需要申报进口和出口等的原因。

Karaf确实可以帮助您解决某些依赖关系,例如功能文件。 如果您有一个功能定义maven项目,则所有编译范围依赖项都可以包含在一个功能文件中。

但是,OSGi解析器只查看当前可用的捆绑包,仅此而已,如果您想要某种 automagic ,则无法连接到maven。解决你需要的外部依赖关系,以确保你有 a)启用了OBR解析器(这取决于您使用的karaf版本,其中已包含4.x)和
b)手头有一个OBR存储库,Karaf Cave将是在这种情况下寻找的项目,因为它可以像maven存储库之上的代理一样驻留。