一、参考文献
http://blog.youkuaiyun.com/u011154682/article/details/11674921
二、步骤
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
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