gpt4 book ai didi

java - maven-bundle-plugin 嵌入依赖项无法将包部署到 OSGi 容器中

转载 作者:行者123 更新时间:2023-12-01 23:57:19 24 4
gpt4 key购买 nike

我有一个 Maven 项目泛光灯。它与 eclipse 一起运行良好。然后我使用bundle-plugin生成bundle并将所有依赖项嵌入到单个目标bundle中 <embed-dependenciy> 。这是 pom.xml:

<groupId>net.floodlightcontroller</groupId>
<artifactId>floodlight</artifactId>
<version>master</version>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Bundle-Activator>net.floodlightcontroller.core.Activator</Bundle-Activator>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
</plugins>
<build>

我已经检查了目标结构。所有依赖项都包含在内。然后我检查manifest.mf:

Import-Package:  
COM.jrockit.reflect,COM.newmonics.PercClassLoader,com.google.protobuf,com.informix.jdbc,
com.kenai.jnr.x86asm,groovy.lang,javax.annotation,javax.jms,javax.mail,
javax.mail.internet,javax.management,javax.naming,javax.net,javax.net.ssl,javax.script,
*
*
*

我想知道为什么它仍然导入这么多包,因为我已经将所有依赖项嵌入到单个包中。当我将包部署到 OSGi 容器并启动它时,出现错误:

Unable to start bundle 402: Unresolved constraint in bundle floodlight [402]: 
Unable to resolve 402.0: missing requirement [402.0] osgi.wiring.package;
(osgi.wiring.package=COM.jrockit.reflect)

COM.jrockit.reflect 是导入包中列出的第一个包。但它没有列在导出包中。运行时需要这个包吗?谁能帮我吗?

最佳答案

这是一种可悲的做法,许多 jars 在代码中的依赖项比它们在 pom.xml 中声明的依赖项还要多。它们通常位于“桥接”环境的代码部分中。 IE。当 jar 在 jrockit 或 groovy 中执行时,它可以利用它,但核心代码并不真正需要这种依赖关系。此外,javax 包可能应该从您的应用程序服务器导入。这些通常在 Maven 的“提供”范围内。

一般来说,您可以将这些依赖项设置为可选,并祈祷没有核心代码路径。您可以在 bnd 中将它们设置为可选:

<_import-package>
javax.*,
COM.jrockit.*;
COM.newmonics.*;
com.google.protobuf;
com.informix.jdbc;
com.kenai.jnr.x86asm;
groovy.lang;
resolution:=optional,
*
</_import-package>

不要忘记末尾的“*”,它为正常导入提供了掩码。

关于java - maven-bundle-plugin 嵌入依赖项无法将包部署到 OSGi 容器中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15369849/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com