gpt4 book ai didi

java - 如何修复 org.osgi.framework.BundleException : Unable to cache bundle?

转载 作者:太空宇宙 更新时间:2023-11-04 09:27:39 25 4
gpt4 key购买 nike

我正在使用OSGi BundleActivator代码。当我尝试使用 Apache Karaf 安装它时,我总是得到 Unable to install bundle mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT: org.osgi.framework.BundleException: Unable to cache bundle: mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT错误。

我尝试遵循的教程在这里:https://www.baeldung.com/osgi

我使用的命令是bundle:install mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT 。尝试添加 -s 标志或使用 install而不是bundle:install ,没有帮助。尝试从 Karaf 根目录和捆绑目录运行它,但没有帮助。

在 Karaf 文件夹中,我尝试设置 org.ops4j.pax.url.mvn.localRepository=/Users/bogdansalyp/.m2/repository ,没有帮助。

清空.m2/repository ,没有帮助。将其复制到 bundle 和 Karaf 文件夹中,但没有帮助。

尝试过mvn installmvn clean install来自不同的目录,没有帮助。

Karaf 是 v4.2.6,maven 是 3.1.1

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>osgi-intro-sample-activator</artifactId>
<name>osgi-intro-sample-activator</name>
<!-- Please, note this is not the usual 'jar'. -->
<packaging>bundle</packaging>

<!-- com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT -->
<parent>
<artifactId>osgi</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>

<!-- Qualified name of the class that exposes the activator iface. -->
<Bundle-Activator>com.baeldung.osgi.sample.activator.HelloWorld</Bundle-Activator>

<!-- One important thing to note: since you are not exporting the package "com.baeldung.osgi.sample.activator", you should at least add it to the Private-Package
instruction. Otherwise, the classes inside the package will not be copied to your bundle, as the default value of this instruction is empty. -->

<Private-Package>com.baeldung.osgi.sample.activator</Private-Package>

</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>

这是我使用的 Java 代码:

package com.baeldung.osgi.sample.activator;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class HelloWorld implements BundleActivator {

public void start(BundleContext ctx) {
System.out.println("Hello World.");
}

public void stop(BundleContext bundleContext) {
System.out.println("Goodbye World.");
}

}

代码结构可以在这里找到:https://github.com/eugenp/tutorials/tree/master/osgi/osgi-intro-sample-activator

预先感谢您的帮助!

最佳答案

您应该将 bundle:install mvn:com.baeldung/osgi-intro-sample-activator/1.0-SNAPSHOT 替换为 bundle:install mvn:com.baeldung/osgi/1.0-SNAPSHOT 因为您的 artifactId 是 osgi。继续关注此链接

关于java - 如何修复 org.osgi.framework.BundleException : Unable to cache bundle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57480441/

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