以编程方式启动OSGi(Equinox)?

我希望能够轻松启动OSGi框架(最好是Equinox)并从java main加载我的pom中列出的所有bundle。 这可能吗?如果是这样,怎么样? 似乎pax工具会这样做,但我似乎找不到任何指示这样的文档。我知道我可以像这样启动Equinox:
BundleContext context = EclipseStarter.startup( ( new String[] { "-console" } ), null );
但我想做更多 - 就像我说的:加载更多的捆绑包,可能会启动一些服务,等等。     
已邀请:
任何OSGi框架(R4.1或更高版本)都可以使用
FrameworkFactory
API以编程方式启动:
ServiceLoader<FrameworkFactory> ffs = ServiceLoader.load(FrameworkFactory.class);
FrameworkFactory ff = ffs.iterator().next();
Map<String,Object> config = new HashMap<String,Object>();
// add some params to config ...
Framework fwk = ff.newFramework(config);
fwk.start();
OSGi框架现在正在运行。由于
Framework
扩展
Bundle
,你可以调用
getBundleContext
并调用所有正常的API方法来操作包,注册服务等。例如
BundleContext bc = fwk.getBundleContext();
bc.installBundle("file:/path/to/bundle.jar");
bc.registerService(MyService.class.getName(), new MyServiceImpl(), null);
// ...
最后你应该等待框架关闭:
fwk.stop();
fwk.waitForStop(0);
重申一下,这种方法适用于任何OSGi框架,包括Equinox和Felix,只需将框架JAR放在类路径上即可。     
这个帖子可能有点陈旧,但无论如何...... Pax对maven url有很好的支持,它甚至还有一个wrap url处理程序,允许你动态地将非osgi jar转换为漂亮整齐的bundle。 http://wiki.ops4j.org/display/paxurl/Mvn+Protocol
    <dependency>
        <groupId>org.ops4j.pax.url</groupId>
        <artifactId>pax-url-wrap</artifactId>
        <version>1.2.5</version>        
    </dependency>
    <dependency>
        <groupId>org.ops4j.pax.url</groupId>
        <artifactId>pax-url-mvn</artifactId>
        <version>1.2.5</version>        
    </dependency>
该命令将是:
install -s mvn:groupId:artifactId:version:classifier
注意:鸡蛋方案 - 您必须首先使用文件:url处理程序安装它们或将它们放入autodeploy目录中。 卡拉夫有这个全部内置它的发行版,所以也许看看卡拉夫发射器源? 第二个注意事项:通过将@snapshots附加到repo URL来启用部署快照,通过ConfigAdmin管理配置 在管理所有POM定义的依赖项方面,请看一下Karaf的功能 - 有一个插件可以生成一个功能XML文件,然后可以用来部署整个应用程序: http://karaf.apache.org/manual/2.1.99-SNAPSHOT/developers-guide/features-maven-plugin.html 此外,这个XML工件可以部署到您的OBR,因此您可以使用vanilla Felix / Equinox / Karaf设置,添加mvn url处理程序并使用您公司的mvn repo进行配置,然后配置整个app =)     
编辑:意识到你想从java里面开始。因为读得不够近而让我感到羞耻 看看这个链接。 http://www.eclipsezone.com/eclipse/forums/t93976.rhtml 实质上
public static void main(String args[]) throws Exception {
  String[] equinoxArgs = {"-console","1234","-noExit"};
  BundleContext context = EclipseStarter.startup(equinoxArgs,null);
  Bundle bundle = context.installBundle(
    "http://www.eclipsezone.com/files/jsig/bundles/HelloWorld.jar");
  bundle.start();
}
编辑:Maven 似乎https://groups.google.com/group/spring-osgi/web/maven-url-handler?pli=1包含OSGi URl处理程序服务,该服务可以采用以下格式的URL并从中加载捆绑包( mvn:// repo / bundle_path)     

要回复问题请先登录注册