karaf配置自定义featrues

来源:互联网 发布:java面向对象选择题 编辑:程序博客网 时间:2024/05/17 01:56

系统环境

JDK :1.8.0_66 x64

Karaf:apache-karaf-4.0.2

maven:Apache Maven 3.3.3


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

下面来介绍如何自己开发一个feature

这里来制作一个名字为:apache-commons-utils的feature,里面包含如下bundle

[html] view plaincopy
  1. <bundle>mvn:commons-io/commons-io/2.4</bundle>  
  2. <bundle>mvn:commons-lang/commons-lang/2.6</bundle>  
  3. <bundle>mvn:commons-discovery/commons-discovery/0.5</bundle>  
  4. <bundle>mvn:commons-math/commons-math/1.2</bundle>  
  5. <bundle>mvn:commons-net/commons-net/3.3</bundle>  
再加上2个配置文件 http.cfg、jdbc.cfg (配置文件只是为了演示如何在安装feature的时候,也同时把配置文件安装上)

新建一个maven项目,groupId:com.lala,artifactId:demo-features,version:1.0.0

1:resources目录下,新建http.cfg、jdbc.cfg两个配置文件,内容随便

2:resources目录下,新建features.xml文件,内容如下:

[html] view plaincopy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <features name="karaf-cellar-4.0.0" xmlns="http://karaf.apache.org/xmlns/features/v1.3.0"   
  3.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  4.           xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.3.0 http://karaf.apache.org/xmlns/features/v1.3.0">  
  5.   
  6.     <feature name="apache-commons-utils" description="apache commons utils" version="1.0.0">  
  7.         <!-- 这个配置文件将会安装到etc/目录下 -->  
  8.         <configfile finalname="/etc/demo-features.jdbc.cfg">mvn:com.lala/demo-features/1.0.0/cfg/jdbc</configfile>  
  9.         <!-- 这个配置文件将会安装到deploy/目录下 -->  
  10.         <configfile finalname="/deploy/demo-features.http.cfg" override="true">mvn:com.lala/demo-features/1.0.0/cfg/http</configfile>  
  11.         <bundle>mvn:commons-io/commons-io/2.4</bundle>  
  12.         <bundle>mvn:commons-lang/commons-lang/2.6</bundle>  
  13.         <bundle>mvn:commons-discovery/commons-discovery/0.5</bundle>  
  14.         <bundle>mvn:commons-math/commons-math/1.2</bundle>  
  15.         <bundle>mvn:commons-net/commons-net/3.3</bundle>  
  16.     <!-- 安装buleprint -->
  17.        <bundle>blueprint:mvn:WHTR.Common/DataImport/1.2.0/xml/blueprint</bundle>

  18.     </feature>  

  19. </features>  

3:在pom.xml加上如下插件配置

[html] view plaincopy
  1. <plugin>  
  2.     <groupId>org.apache.maven.plugins</groupId>  
  3.     <artifactId>maven-resources-plugin</artifactId>  
  4.     <configuration>  
  5.         <useDefaultDelimiters>false</useDefaultDelimiters>  
  6.         <delimiters>  
  7.             <delimiter>${*}</delimiter>  
  8.         </delimiters>  
  9.     </configuration>  
  10.     <executions>  
  11.         <execution>  
  12.             <id>filter</id>  
  13.             <phase>generate-resources</phase>  
  14.             <goals>  
  15.                 <goal>resources</goal>  
  16.             </goals>  
  17.         </execution>  
  18.     </executions>  
  19. </plugin>  
  20. <plugin>  
  21.     <groupId>org.codehaus.mojo</groupId>  
  22.     <artifactId>build-helper-maven-plugin</artifactId>  
  23.     <version>1.9.1</version>  
  24.     <executions>  
  25.         <execution>  
  26.             <id>attach-artifact</id>  
  27.             <phase>package</phase>  
  28.             <goals>  
  29.                 <goal>attach-artifact</goal>  
  30.             </goals>  
  31.             <configuration>  
  32.                 <artifacts>  
  33.                     <artifact>  
  34.                         <file>target/classes/features.xml</file>  
  35.                         <type>xml</type>  
  36.                         <classifier>features</classifier>  
  37.                     </artifact>  
  38.                     <artifact>  
  39.                         <file>target/classes/jdbc.cfg</file>  
  40.                         <type>cfg</type>  
  41.                         <classifier>jdbc</classifier>  
  42.                     </artifact>  
  43.                     <artifact>  
  44.                         <file>target/classes/http.cfg</file>  
  45.                         <type>cfg</type>  
  46.                         <classifier>http</classifier>  
  47.                     </artifact>  
  48.                   <!--安装buleprint-->
  49.                    <artifact>
                            <file>target/webServiceblueprint.xml</file>
                            <type>xml</type>
                            <classifier>blueprint</classifier>
                    </artifact>
  50.                 </artifacts>  
  51.             </configuration>  
  52.         </execution>  
  53.     </executions>  
  54. </plugin>  

注意:这里的artifact、file、type、classifier的配置方法为:

type为file的扩展名,classifier为file的文件名


配置好之后,执行mvn clean install ,mvn clean deploy


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

在featuresRepositories配置项后面加上:mvn:com.lala/demo-features/1.0.0/xml/features


5:修改${karaf.home}/etc/org.ops4j.pax.url.mvn.cfg文件,

在org.ops4j.pax.url.mvn.repositories配置项后面加上:http://192.168.1.100:8080/nexus/content/groups/public  (maven私服的地址)


org.ops4j.pax.url.mvn.settings

org.ops4j.pax.url.mvn.localRepository

这2个配置项,如果你maven本地的仓库地址变了,就需要修改,否则,就不需要修改


5:修改好了之后,重启karaf,执行安装,即可看到效果

[plain] view plaincopy
  1. karaf@root()> feature:install apache-commons-utils  
  2. karaf@root()> list  
  3. START LEVEL 100 , List Threshold: 50  
  4. ID | State  | Lvl | Version | Name  
  5. --------------------------------------------------------  
  6. 52 | Active |  80 | 0.5     | Commons Discovery  
  7. 53 | Active |  80 | 2.4.0   | Commons IO  
  8. 54 | Active |  80 | 2.6     | Commons Lang  
  9. 55 | Active |  80 | 1.2     | Apache Commons Math Bundle  
  10. 56 | Active |  80 | 3.3.0   | Commons Net  
  11. karaf@root()>  
0 0
原创粉丝点击