日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Apache Karaf自定义feature

發布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apache Karaf自定义feature 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

系統環境

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

<bundle>mvn:commons-io/commons-io/2.4</bundle> <bundle>mvn:commons-lang/commons-lang/2.6</bundle> <bundle>mvn:commons-discovery/commons-discovery/0.5</bundle> <bundle>mvn:commons-math/commons-math/1.2</bundle> <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文件,內容如下:

<?xml version="1.0" encoding="UTF-8"?> <features name="karaf-cellar-4.0.0" 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="apache-commons-utils" description="apache commons utils" version="1.0.0"><!-- 這個配置文件將會安裝到etc/目錄下 --><configfile finalname="/etc/demo-features.jdbc.cfg">mvn:com.lala/demo-features/1.0.0/cfg/jdbc</configfile><!-- 這個配置文件將會安裝到deploy/目錄下 --><configfile finalname="/deploy/demo-features.http.cfg" override="true">mvn:com.lala/demo-features/1.0.0/cfg/http</configfile><bundle>mvn:commons-io/commons-io/2.4</bundle><bundle>mvn:commons-lang/commons-lang/2.6</bundle><bundle>mvn:commons-discovery/commons-discovery/0.5</bundle><bundle>mvn:commons-math/commons-math/1.2</bundle><bundle>mvn:commons-net/commons-net/3.3</bundle></feature></features>
3:在pom.xml加上如下插件配置

<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><artifact><file>target/classes/jdbc.cfg</file><type>cfg</type><classifier>jdbc</classifier></artifact><artifact><file>target/classes/http.cfg</file><type>cfg</type><classifier>http</classifier></artifact></artifacts></configuration></execution></executions> </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,執行安裝,即可看到效果

karaf@root()> feature:install apache-commons-utils karaf@root()> list START LEVEL 100 , List Threshold: 50 ID | State | Lvl | Version | Name -------------------------------------------------------- 52 | Active | 80 | 0.5 | Commons Discovery 53 | Active | 80 | 2.4.0 | Commons IO 54 | Active | 80 | 2.6 | Commons Lang 55 | Active | 80 | 1.2 | Apache Commons Math Bundle 56 | Active | 80 | 3.3.0 | Commons Net karaf@root()>


總結

以上是生活随笔為你收集整理的Apache Karaf自定义feature的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。