测试环境:JBoss wildfly beta1环境下,使用jndi可以方便的加载osgi容器中服务
InitialContext ctx = null;
try {
ctx = new InitialContext();
String jndiName = "osgi:service/" + ExampleService.class.getName();
ExampleService offers =
(ExampleService) ctx.lookup(jndiName);
System.out.println(offers.sayHello("test"));
} catch (NamingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
其中ExampleService是在osgi中已经注册的servie。