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

启动成功例如以下:


osgi实战学习之路:2. maven+maven-bundle-plugin+karaf搭建osgi之HelloWorld



安装 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-SNAPSHOT

bundle:install -s mvn:com.demo.hello/mvn-hello-consumer/0.0.1-SNAPSHOT


执行结果:


osgi实战学习之路:2. maven+maven-bundle-plugin+karaf搭建osgi之HelloWorld





源码下载


相关文章:

  • 2021-07-23
  • 2021-10-27
  • 2021-04-11
  • 2021-06-10
  • 2022-12-23
  • 2022-02-19
猜你喜欢
  • 2021-05-18
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-14
  • 2021-08-21
  • 2021-09-19
相关资源
相似解决方案