发布karaf的features

转载自:http://blog.csdn.net/u011154682/article/details/11674921


Karaf的features是其本身的一大亮点,通过features可以完成某个功能相关bundle的安装和卸载,极大的方便了对bundle的管理。

Karaf的最新版本是2.3.2,通过features:install 命令,安装的features都是在data目录下,这个目录你可以整个的清空,就可以恢复karaf的最初状态。如果我们在开发过程中,打算把你弄好的环境发布出去,该如何完成呢?

带着这个问题,查了karaf的用户手册,发现karaf也提供了相应的支持,不得不感叹老外开发的东西就是全面,只要你有需求,人家都帮你弄好了。

1.安装features插件

[html]  view plain copy
  1. <plugin>  
  2.                 <groupId>org.apache.karaf.tooling</groupId>  
  3.                 <artifactId>features-maven-plugin</artifactId>  
  4.                 <version>2.3.2</version>  
  5.   
  6.                 <executions>  
  7.                     <execution>  
  8.                         <id>add-features-to-repo</id>  
  9.                         <phase>generate-resources</phase>  
  10.                         <goals>  
  11.                             <goal>add-features-to-repo</goal>  
  12.                         </goals>  
  13.                         <configuration>  
  14.                             <descriptors>  
  15.                                 <descriptor>file:D:/myJavaTools/apache-karaf-2.3.2/etc/drools.xml</descriptor>  
  16.                                 <!--<descriptor>mvn:org.apache.activemq/activemq-karaf/5.8.0/xml/features</descriptor>-->  
  17.                                 <!--<descriptor>mvn:org.apache.karaf.assemblies.features/standard/2.3.2/xml/features</descriptor>-->  
  18.                             </descriptors>  
  19.                             <features>  
  20.                                 <feature>war</feature>  
  21.                                 <feature>webconsole</feature>  
  22.                                 <feature>drools-common</feature>  
  23.   
  24.                             </features>  
  25.                             <repository>${project.build.directory}/features-repo</repository>  
  26.                         </configuration>  
  27.                     </execution>  
  28.                 </executions>  
  29.             </plugin>  
说明:这里我自定义了drools.xml,这个文件时我在drools的官网上下载到本地的,我打算在karaf中预先安装war,webconsole以及drools-common三种features。
执行mvn install后,会在target/features-repo下看到生成的jar包,这些jar是以maven库的格式组织的。

2.修改karaf的启动配置

打开 org.apache.karaf.features.cfg文件,修改如下:
[html]  view plain copy
  1. ################################################################################  
  2. #  
  3. #    Licensed to the Apache Software Foundation (ASF) under one or more  
  4. #    contributor license agreements.  See the NOTICE file distributed with  
  5. #    this work for additional information regarding copyright ownership.  
  6. #    The ASF licenses this file to You under the Apache License, Version 2.0  
  7. #    (the "License"); you may not use this file except in compliance with  
  8. #    the License.  You may obtain a copy of the License at  
  9. #  
  10. #       http://www.apache.org/licenses/LICENSE-2.0  
  11. #  
  12. #    Unless required by applicable law or agreed to in writing, software  
  13. #    distributed under the License is distributed on an "AS IS" BASIS,  
  14. #    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  15. #    See the License for the specific language governing permissions and  
  16. #    limitations under the License.  
  17. #  
  18. ################################################################################  
  19.   
  20. respectStartLvlDuringFeatureStartup=false  
  21.   
  22. #  
  23. # Comma separated list of features repositories to register by default  
  24. #  
  25. featuresRepositories=mvn:org.apache.karaf.assemblies.features/standard/2.3.2/xml/features,mvn:org.apache.karaf.assemblies.features/enterprise/2.3.2/xml/features,file:D:/myJavaTools/apache-karaf-2.3.2/etc/drools.xml  
  26.   
  27. #  
  28. # Comma separated list of features to install at startup  
  29. #  
  30. featuresBoot=config,ssh,management,kar,war,webconsole,drools-common  
  31.   
  32. #  
  33. # Defines if the boot features are started in asynchronous mode (in a dedicated thread)  
  34. #  
  35. featuresBootAsynchronous=false  
在featuresRepositories中增加我刚才自定义的drools features文件;然后在featuresBoot增加war,webconsole,drools-common
[html]  view plain copy
  1.   

  3.复制生成的jar到system目录

复制生成的jar包目录下的文件到karaf下的system目录
以上操作完成后,可以尝试清空karaf下的data目录,然后重启karaf,输入 features:list,哈哈,发现war,webconsole以及drools以及安装好了
附件:drools.xml文件
[html]  view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <features name="camel-drools-example-6.0.0.CR3"  
  3.           xmlns="http://karaf.apache.org/xmlns/features/v1.0.0"  
  4.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  5.           xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.0.0 http://karaf.apache.org/xmlns/features/v1.0.0">  
  6.   
  7.   <repository>mvn:org.apache.camel.karaf/apache-camel/2.10.3/xml/features</repository>  
  8.   <repository>mvn:org.apache.cxf.karaf/apache-cxf/2.6.6/xml/features</repository>  
  9.   
  10.   <feature name="drools-common" version="6.0.0.CR3" description="Drools Commons">  
  11.     <feature version="[2.6,3.0)">cxf-specs</feature>  
  12.     <bundle>mvn:com.google.protobuf/protobuf-java/2.5.0</bundle>  
  13.     <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.antlr/3.5_1</bundle>  
  14.     <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream/1.4.3_1</bundle>  
  15.     <bundle start-level='10'>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.2/1.9.0</bundle>  
  16.     <bundle start-level='10'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-xjc/2.2.1.1_2</bundle>  
  17.     <bundle start-level='10'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jaxb-impl/2.2.1.1_2</bundle>  
  18.     <bundle>mvn:org.mvel/mvel2/2.1.6.Final</bundle>  
  19.     <bundle>wrap:mvn:org.eclipse.jdt.core.compiler/ecj/4.2.1$Bundle-SymbolicName=Eclipse-JDT-Compiler&Bundle-Version=4.2.1</bundle>  
  20.     <bundle>wrap:mvn:org.codehaus.janino/janino/2.6.1$Bundle-SymbolicName=Codehaus-Janino&Bundle-Version=2.6.1</bundle>  
  21.     <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.quartz/2.1.6_1</bundle>  
  22.     <bundle>mvn:org.apache.geronimo.specs/geronimo-atinject_1.0_spec/1.0</bundle>  
  23.     <bundle>wrap:mvn:javax.enterprise/cdi-api/1.0-SP4</bundle>  
  24.   </feature>  
  25.   
  26.   <feature name="drools-module" version="6.0.0.CR3" description="Drools core">  
  27.     <feature version="6.0.0.CR3">drools-common</feature>  
  28.     <feature version="6.0.0.CR3">kie</feature>  
  29.     <bundle>mvn:org.drools/drools-core/6.0.0.CR3</bundle>  
  30.     <bundle>mvn:org.drools/drools-compiler/6.0.0.CR3</bundle>  
  31.     <bundle>mvn:org.drools/drools-osgi-integration/6.0.0.CR3</bundle>  
  32.   </feature>  
  33.   
  34.   <feature name="drools-templates" version="6.0.0.CR3" description="Drools Templates">  
  35.     <bundle>mvn:org.drools/drools-templates/6.0.0.CR3</bundle>  
  36.   </feature>  
  37.   
  38.   <feature name="drools5-spring" version="6.0.0.CR3" description="Drools5 Spring">  
  39.     <feature version="[3.0,4.0)">spring</feature>  
  40.     <bundle>mvn:org.drools/drools-spring-legacy5/6.0.0.CR3</bundle>  
  41.   </feature>  
  42.   
  43.   <feature name="drools5-camel" version="6.0.0.CR3" description="Drools5 Camel">  
  44.     <feature version="6.0.0.CR3">drools-module</feature>  
  45.     <feature version="6.0.0.CR3">drools5-spring</feature>  
  46.     <feature version="2.10.3">camel</feature>  
  47.     <feature version="2.10.3">camel-cxf</feature>  
  48.     <feature version="[2.6,3.0)">cxf-specs</feature>  
  49.     <feature version="[2.6,3.0)">cxf-core</feature>  
  50.     <feature version="[2.6,3.0)">cxf-jaxrs</feature>  
  51.     <bundle>mvn:org.drools/drools-camel-legacy5/6.0.0.CR3</bundle>  
  52.   </feature>  
  53.   
  54.   <feature name="drools-decisiontable" description="Drools Decision Tables" version="6.0.0.CR3">  
  55.     <feature version="6.0.0.CR3">drools-module</feature>  
  56.     <feature version="6.0.0.CR3">drools-templates</feature>  
  57.     <bundle>mvn:commons-codec/commons-codec/1.7</bundle>  
  58.     <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi/3.9_2</bundle>  
  59.     <bundle>mvn:org.drools/drools-decisiontables/6.0.0.CR3</bundle>  
  60.   </feature>  
  61.   
  62.   <feature name="drools-jpa" version="6.0.0.CR3" description="Drools JPA">  
  63.     <feature version="6.0.0.CR3">drools-module</feature>  
  64.     <feature version="[3.0,4.0)">spring-orm</feature>  
  65.     <feature version="[1.0.1,2.0)">jpa</feature>  
  66.     <bundle>mvn:org.drools/drools-persistence-jpa/6.0.0.CR3</bundle>  
  67.   </feature>  
  68.   
  69.   <feature name="kie" version="6.0.0.CR3">  
  70.     <bundle>mvn:org.kie/kie-api/6.0.0.CR3</bundle>  
  71.     <bundle>mvn:org.kie/kie-internal/6.0.0.CR3</bundle>  
  72.   </feature>  
  73.   
  74.   <feature name="kie-spring" version="6.0.0.CR3">  
  75.     <feature version="6.0.0.CR3">kie</feature>  
  76.     <feature version="6.0.0.CR3">drools-jpa</feature>  
  77.     <feature version="6.0.0.CR3">jbpm</feature>  
  78.     <feature version="6.0.0.CR3">jbpm-human-task</feature>  
  79.     <bundle>mvn:org.kie/kie-spring/6.0.0.CR3</bundle>  
  80.   </feature>  
  81.   
  82.   <feature name="kie-aries-blueprint" version="6.0.0.CR3">  
  83.     <feature version="6.0.0.CR3">kie</feature>  
  84.     <feature version="6.0.0.CR3">drools-jpa</feature>  
  85.     <feature version="6.0.0.CR3">jbpm</feature>  
  86.     <feature version="6.0.0.CR3">jbpm-human-task</feature>  
  87.     <bundle>mvn:org.kie/kie-aries-blueprint/6.0.0.CR3</bundle>  
  88.   </feature>  
  89.   
  90.   <feature name="kie-camel" version="6.0.0.CR3">  
  91.     <feature version="6.0.0.CR3">kie</feature>  
  92.     <feature version="6.0.0.CR3">kie-spring</feature>  
  93.     <feature version="6.0.0.CR3">jbpm</feature>  
  94.     <feature version="2.10.3">camel</feature>  
  95.     <feature version="2.10.3">camel-cxf</feature>  
  96.     <feature version="[2.6,3.0)">cxf-specs</feature>  
  97.     <feature version="[2.6,3.0)">cxf-core</feature>  
  98.     <feature version="[2.6,3.0)">cxf-jaxrs</feature>  
  99.     <bundle>mvn:org.kie/kie-camel/6.0.0.CR3</bundle>  
  100.   </feature>  
  101.   
  102.   <feature name="jbpm" version="6.0.0.CR3" description="jBPM engine">  
  103.     <feature version="6.0.0.CR3">drools-module</feature>  
  104.     <bundle>mvn:joda-time/joda-time/1.6.2</bundle>  
  105.     <bundle>mvn:org.jbpm/jbpm-flow-builder/6.0.0.CR3</bundle>  
  106.     <bundle>mvn:org.jbpm/jbpm-flow/6.0.0.CR3</bundle>  
  107.     <bundle>mvn:org.jbpm/jbpm-bpmn2/6.0.0.CR3</bundle>  
  108.   </feature>  
  109.   
  110.   <feature name="jbpm-human-task" version="6.0.0.CR3" description="jBPM engine">  
  111.     <feature version="6.0.0.CR3">drools-module</feature>  
  112.     <feature version="6.0.0.CR3">drools-jpa</feature>  
  113.     <feature version="6.0.0.CR3">jbpm</feature>  
  114.     <bundle>mvn:org.apache.geronimo.specs/geronimo-jta_1.1_spec/1.1.1</bundle>  
  115.     <bundle>mvn:org.apache.geronimo.specs/geronimo-jpa_2.0_spec/1.1</bundle>  
  116.     <bundle>mvn:org.apache.geronimo.specs/geronimo-jms_1.1_spec/1.1.1</bundle>  
  117.     <bundle>wrap:mvn:org.apache.geronimo.specs/geronimo-jacc_1.1_spec/1.0</bundle>  
  118.     <bundle>wrap:mvn:org.jboss.seam.transaction/seam-transaction-api/3.1.0.Final</bundle>  
  119.     <bundle>wrap:mvn:org.jboss.weld/weld-core/1.1.13.Final</bundle>  
  120.     <bundle>wrap:mvn:org.jboss.solder/solder-api/3.2.0.Final</bundle>  
  121.     <bundle>wrap:mvn:org.apache.helix/helix-core/0.6.1-incubating</bundle>  
  122.     <bundle>mvn:org.kie.commons/kie-nio2-model/6.0.0.CR3</bundle>  
  123.     <bundle>mvn:org.kie.commons/kie-commons-cdi/6.0.0.CR3</bundle>  
  124.     <bundle>mvn:org.kie.commons/kie-commons-validation/6.0.0.CR3</bundle>  
  125.     <bundle>mvn:org.kie.commons/kie-commons-data/6.0.0.CR3</bundle>  
  126.     <bundle>mvn:org.kie.commons/kie-commons-io/6.0.0.CR3</bundle>  
  127.     <bundle>mvn:org.jbpm/jbpm-audit/6.0.0.CR3</bundle>  
  128.     <bundle>mvn:org.jbpm/jbpm-shared-services/6.0.0.CR3</bundle>  
  129.     <bundle>mvn:org.jbpm/jbpm-runtime-manager/6.0.0.CR3</bundle>  
  130.     <bundle>mvn:org.jbpm/jbpm-human-task-core/6.0.0.CR3</bundle>  
  131.     <bundle>mvn:org.jbpm/jbpm-human-task-workitems/6.0.0.CR3</bundle>  
  132.     <bundle>mvn:org.jbpm/jbpm-persistence-jpa/6.0.0.CR3</bundle>  
  133.   </feature>  
  134.   
  135.   <feature name="drools5-camel-example" version="6.0.0.CR3" description="Drools5 Spring Camel Example">  
  136.     <feature version="6.0.0.CR3">drools-module</feature>  
  137.     <feature version="6.0.0.CR3">drools-decisiontable</feature>  
  138.     <feature version="6.0.0.CR3">drools5-spring</feature>  
  139.     <feature version="6.0.0.CR3">drools5-camel</feature>  
  140.     <bundle>mvn:org.drools/drools-camel-example/6.0.0.CR3</bundle>  
  141.   </feature>  
  142.   
  143.   <feature name="drools-camel-example" version="6.0.0.CR3" description="Drools Kie Spring Camel Example">  
  144.     <feature version="6.0.0.CR3">drools-module</feature>  
  145.     <feature version="6.0.0.CR3">drools-decisiontable</feature>  
  146.     <feature version="6.0.0.CR3">kie-spring</feature>  
  147.     <feature version="6.0.0.CR3">kie-camel</feature>  
  148.     <bundle start-level="100">mvn:org.drools/spring-camel-drools-decision-table-example/6.0.0.CR3</bundle>  
  149.   </feature>  
  150.   
  151.   <feature name="drools-blueprint-camel-example" version="6.0.0.CR3" description="Drools Kie Blueprint Camel Example">  
  152.     <feature version="6.0.0.CR3">drools-module</feature>  
  153.     <feature version="6.0.0.CR3">drools-decisiontable</feature>  
  154.     <feature version="6.0.0.CR3">kie-aries-blueprint</feature>  
  155.     <feature version="6.0.0.CR3">kie-camel</feature>  
  156.     <bundle>mvn:org.drools/blueprint-camel-drools-decision-table-example/6.0.0.CR3</bundle>  
  157.   </feature>  
  158.   
  159.   <feature name="jbpm-example" version="6.0.0.CR3" description="jBPM Spring Example">  
  160.     <feature version="6.0.0.CR3">jbpm</feature>  
  161.     <bundle>mvn:org.drools/jbpm-osgi-example/6.0.0.CR3</bundle>  
  162.   </feature>  
  163.   
  164. </features>  

总结:以上的过程,对于大家来说,有什么启示吗?我想大家肯定会想到,在使用karaf开发osgi的项目过程中,把相关的功能通过features进行组织,然后按照上面的方式,把预先必须的features预先设置,然后进行发布,系统提供的其他features也包括在你发布的karaf里面,可以灵活的安装和卸载。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值