【发布时间】:2019-12-20 04:04:17
【问题描述】:
我正在使用 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 install 和mvn 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
提前感谢您的帮助!
【问题讨论】:
标签: java osgi apache-karaf osgi-bundle