jdk版本号
jdk:1.7
karaf:
版本号:apache-karaf-3.0.1
下载地址:
http://pan.baidu.com/s/1qWM4Y1u
http://karaf.apache.org/
配置本地仓库:
參考:http://blog.csdn.net/wobendiankun/article/details/25333113
启动karaf:
karaf_home/bin/karaf.bat
启动成功例如以下:
安装 mvn-hello-provider 到本地仓库
hello.java
package com.demo.hello; public class Hello { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public Hello() { this.name="jack"; } public void sayHi(){ System.out.println("hi:\t"+this.name); } }
pom.xml:
执行命令:
mvn clean install
安装 mvn-hello-consumer 到本地仓库
HelloClientActivator.java
package com.demo.hello.activator; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import com.demo.hello.Hello; public class HelloClientActivator implements BundleActivator{ Hello hello; public void start(BundleContext context) throws Exception { hello=new Hello(); hello.sayHi(); } public void stop(BundleContext context) throws Exception { hello=null; } }
pom.xml
执行命令:
mvn clean install
部署bundle到karaf
注意部署顺序
先部署,mvn-hello-provider,再mvn-hello-consumer
在karaf命令行中执行命令:
bundle:install -s mvn:com.demo.hello/mvn-hello-provider/0.0.1-SNAPSHOTbundle:install -s mvn:com.demo.hello/mvn-hello-consumer/0.0.1-SNAPSHOT
执行结果:
源码下载