Karaf的features是其本身的一大亮点,通过features可以完成某个功能相关bundle的安装和卸载,极大的方便了对bundle的管理。
Karaf的最新版本是2.3.2,通过features:install 命令,安装的features都是在data目录下,这个目录你可以整个的清空,就可以恢复karaf的最初状态。如果我们在开发过程中,打算把你弄好的环境发布出去,该如何完成呢?
带着这个问题,查了karaf的用户手册,发现karaf也提供了相应的支持,不得不感叹老外开发的东西就是全面,只要你有需求,人家都帮你弄好了。
1.安装features插件
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>features-maven-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>add-features-to-repo</id>
<phase>generate-resources</phase>
<goals>
<goal>add-features-to-repo</goal>
</goals>
<configuration>
<descriptors>
<descriptor>file:D:/myJavaTools/apache-karaf-2.3.2/etc/drools.xml</descriptor>
<!--<descriptor>mvn:org.apache.activemq/activemq-karaf/5.8.0/xml/features</descriptor>-->
<!--<descriptor>mvn:org.apache.karaf.assemblies.features/standard/2.3.2/xml/features</descriptor>-->
</descriptors>
<features>
<feature>war</feature>
<feature>webconsole</feature>
<feature>drools-common</feature>
</features>
<repository>${project.build.directory}/features-repo</repository>
</configuration>
</execution>
</executions>
</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文件,修改如下:
################################################################################
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License