gpt4 book ai didi

java - org.osgi.framework.BundleException : Unresolved constraint in bundle SampleModel

转载 作者:行者123 更新时间:2023-12-01 23:38:53 25 4
gpt4 key购买 nike

我正在尝试以编程方式启动 OSGi 框架。我为此使用 Felix 框架。下面是我将启动 OSGi 容器的代码。

public GoldeneyeApp() {

try {

FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<String, String>();

//TODO: add some config properties
Framework framework = frameworkFactory.newFramework(config);
framework.start();

BundleContext bundleContext = framework.getBundleContext();

modulesNameVersionHolder.put("SampleModel", "1.0.0");

List<Bundle> installedBundles = new LinkedList<Bundle>();

String basePath = "C:\\ClientTool\\LocalStorage";

for (Map.Entry<String, String> entry : modulesNameVersionHolder.entrySet()) {

String version = entry.getValue();
final String filename = name + Constants.DASH + version + Constants.DOTJAR;
final String localFilename = Constants.FILE_PROTOCOL + basePath+ File.separatorChar + filename;

installedBundles.add(bundleContext.installBundle(localFilename));
}

for (Bundle bundle : installedBundles) {
bundle.start(); // this line throws an exception as soon as I start SampleModel bundle
}
} catch (BundleException e) {
e.printStackTrace();
}
}

在上面的代码中,我尝试安装并启动我创建的一个简单的 OSGi 模块(SampleModel jar)。一旦我尝试启动该模块,我总是会收到以下异常 -

org.osgi.framework.BundleException: Unresolved constraint in bundle SampleModel [6]: Unable to resolve 6.0: missing requirement [6.0] osgi.wiring.package; (&(osgi.wiring.package=net.sf.cglib.core)(version>=2.1.3)(!(version>=3.0.0)))
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
at com.host.stream.goldeneye.GoldeneyeApp.<init>(GoldeneyeApp.java:62)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1345)
at com.host.jetstream.application.JetstreamApplication.getInstance(JetstreamApplication.java:71)
at com.host.jetstream.application.JetstreamApplication.main(JetstreamApplication.java:94)

下面是我的 SampleModel pom.xml 文件 -

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>com.host.Domain</groupId>
<artifactId>DomainParent</artifactId>
<version>1.6.1-RELEASE</version>
</parent>

<!-- POM Information about the Project -->
<modelVersion>4.0.0</modelVersion>
<groupId>com.host.sample.model</groupId>
<artifactId>SampleModel</artifactId>
<version>1.0.0</version>

<!-- Packing Type is bundle for OSGI Library Bundle -->
<packaging>bundle</packaging>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.cglib</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.0</version><!--$NO-MVN-MAN-VER$ -->
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>4.3.0</version><!--$NO-MVN-MAN-VER$ -->
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>

<!-- Build Configration -->
<build>
<plugins>
<!-- Apache Felix Bundle Plugin - For Generation of Manifest after Compile phase -->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<manifestLocation>src/main/resources/META-INF</manifestLocation>
<instructions>
<Bundle-SymbolicName>SampleModel</Bundle-SymbolicName>
<Bundle-Activator>com.host.sample.model.samplemodel.activator.Activator</Bundle-Activator>
<Import-Package>*,
org.springframework.beans.factory;version="[3.0.5.RELEASE,4.0.0)",
org.springframework.beans.factory.config;version="[3.0.5.RELEASE,4.0.0)",
net.sf.cglib.core;version="[2.1.3,3.0.0)",
net.sf.cglib.proxy;version="[2.1.3,3.0.0)",
net.sf.cglib.reflect;version="[2.1.3,3.0.0)"
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

<!-- Configuration of repositories for dependency resolution -->
<repositories>
<!-- Domain Bundles Repository -->
<!-- This is needed to locate the Domain Parent project. Other repositories
come from the parent. -->
<repository>
<id>releases</id>
<url>http://nxDomain/content/repositories/releases/</url>
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>thirdparty</id>
<url>http://nxDomain/content/repositories/thirdparty/</url>
<releases>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>

最佳答案

您正在 list 中使用“Import-Package: net.sf...”,但尚未将 CGLIB(或 Spring Framework)安装到 OSGI 运行时中。如果 Import-Package 无法解析每个必需的包,您的 bundle 将无法启动。

编辑:我忘了我有这个:https://gist.github.com/sheenobu/5935468 。如果 pax-url 正常工作,您就可以从任意 url 开始安装。

EDIT2:还要清除框架缓存,否则您最终会多次安装软件包。或者检查该软件包是否已作为 bundle 安装,如果是,则不要安装它。

关于java - org.osgi.framework.BundleException : Unresolved constraint in bundle SampleModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18259944/

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