项目中需要在karaf中集成cxf-dosgi-discovery-distributed特性,所以需要在karaf开启时启动cxf-dosgi-discovery-distributed的feature,只需要在etc/org.apache.karaf.features.cfg中加入如下的片段即可:
“mvn:org.apache.cxf.dosgi/cxf-dosgi/1.6.0/xml/features”和“cxf-dosgi-discovery-distributed”为加入的部分
featuresRepositories=mvn:org.apache.karaf.features/standard/3.0.3/xml/features,mvn:org.apache.karaf.features/enterprise/3.0.3/xml/features,mvn:org.ops4j.pax.web/pax-web-features/3.1.4/xml/features,mvn:org.apache.karaf.features/spring/3.0.3/xml/features,mvn:org.apache.cxf.dosgi/cxf-dosgi/1.6.0/xml/features
#
# Comma separated list of features to install at startup
#
featuresBoot=config,standard,region,package,kar,ssh,management,cxf-dosgi-discovery-distributed
上述配置以后,karaf启动时就会从maven仓库下载所需要的feature并启动。
但是这样需要每次都从maven仓库中取,网络状况不好的时候很费时。最好的方式是把这些feature都放在本地。幸好karaf的system目录就是专干这个的。可以把feature相关的bundle都放在system中,这样就不再需要去maven仓库中取了。
利用karaf-maven-plugin的features-add-to-repository即可实现:
<plugin>
<groupId>org.apache.karaf.tooling</groupId>
<artifactId>karaf-maven-plugin</artifactId>
<version>3.0.3</version>
<executions>
<execution>
<id>features-add-to-repo</id>
<phase>generate-resources</phase>
<goals>
<goal>features-add-to-repository</goal>
</goals>
<configuration>
<descriptors>
<descriptor>mvn:org.apache.cxf.dosgi/cxf-dosgi/1.6.0/xml/features</descriptor>
<descriptor>mvn:org.apache.karaf.features/standard/3.0.3/xml/features</descriptor>
</descriptors>
<features>
<feature>http-whiteboard</feature>
<feature>cxf-dosgi-discovery-distributed</feature>
</features>
<repository>target/features-repo</repository>
</configuration>
</execution>
</executions>
</plugin>
生成的maven结构的目录会放在target/features-repo中,只需要把里面的目录原封不动拷贝到karaf的system目录下即可。下次启动时feature就会从这里面获取了。