无法在Apache ServiceMix中启动OSGI包

时间:2017-11-04 19:20:20

标签: java osgi osgi-bundle apache-servicemix

我想要创建OSGI捆绑包。我创建了一个简单的类:

public class Activator implements BundleActivator {
public void start(BundleContext bundleContext) throws Exception {
    System.out.println("::::START MAIL BUNDLE::::");
}

public void stop(BundleContext bundleContext) throws Exception {
    System.out.println("::::STOP MAIL BUNDLE::::");
}
}

我的pom.xml

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

<build>
    <plugins>
        <plugin>
            <inherited>true</inherited>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <executions>
                <execution>
                    <id>osgi-bundle</id>
                    <goals>
                        <goal>bundle</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <instructions>
                            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                            <Bundle-Version>${project.version}</Bundle-Version>
                            <Import-Package>
                                *;resolution:=optional
                            </Import-Package>
                        </instructions>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

我使用Service Mix。我在目标文件夹中添加org.osgi.core-6.0.0.jar和我的jar。我的捆绑包处于活动状态,但在karaf控制台中启动/停止捆绑时,我看不到我的消息。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您必须在maven-bundle-config中设置<Bundle-Activator>your.package.name.Activator</Bundle-Activator>。 另请注意,永远不要部署org.osgi.core或org.osgi.componendium。核心软件包由OSGi框架和个人规范部署的汇编部署。