发布karaf的features

本文介绍如何使用Maven构建OSGi Bundle,并通过Karaf Feature进行管理。包括环境搭建、配置文件编辑及安装使用步骤。

一、参考文献

http://blog.youkuaiyun.com/u011154682/article/details/11674921

如何构建OSGI的bundle

二、步骤

2.1 环境 window7、apache-karaf-4.1.2、maven

2.2 简介:karaf中的feature通常是几个bundle的集合,安装这个feature的时候,相应的bundle也都会被安装上去,用来管理bundle很方便

2.3 新建一个maven项目,resources目录下,新建features.xml文件,内容如下

<?xml version="1.0" encoding="UTF-8"?>
<features name="enterprise-4.1.2" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.3.0 http://karaf.apache.org/xmlns/features/v1.3.0">
    <feature name="karaf-test" description="karaf test">
        <bundle>mvn:com.clover286/service/1.0-SNAPSHOT</bundle>
        <bundle>mvn:com.clover286/consumer/1.0-SNAPSHOT</bundle>
    </feature>
</features>

2.4 pom如下

<?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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.clover286</groupId>
    <artifactId>features</artifactId>
    <version>1.0</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <useDefaultDelimiters>false</useDefaultDelimiters>
                    <delimiters>
                        <delimiter>${*}</delimiter>
                    </delimiters>
                </configuration>
                <executions>
                    <execution>
                        <id>filter</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
                <executions>
                    <execution>
                        <id>attach-artifact</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>target/classes/features.xml</file>
                                    <type>xml</type>
                                    <classifier>features</classifier>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

2.5 执行mvn clean install

2.6 修改${karaf.home}/etc/org.apache.karaf.features.cfg文件

在featuresRepositories配置项后面加上:mvn:${groupId}/${artifactId}/${version} /xml/features

此处为:mvn:com.clover286/features/1.0/xml/features

以上${groupId}等指的是features模块的pom

111608_epj9_2702165.png

2.7 启动karaf,查看是否能检测到feature

list | grep karaf-test

(注意:karaf-test是你的features.xml里设定的feature名字)

2.8 安装feature

feature:install karaf-test

2.9 注意:当2.7中找不到自己的features时,可以试下清空${karaf-hme}\data\cache,这里会缓存bundle

转载于:https://my.oschina.net/Cubicluo/blog/1538999

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值