我目前正在尝试使用OSGI,并决定选择一个稍微不典型的OSGI用例.我想在命令行应用程序中使用它.我想要一个带有main(..)一些标志和参数的方法,做一些事情并再次关闭.我不想要的是启动Apache Karaf(或类似的)并在OSGI控制台中运行命令(这可能成为一个可选功能).
为什么OSGI首先用于命令行应用程序?该应用程序应该使用相同库的不同版本(即弹性搜索).而且仅仅因为它当然是坏事.
我应该在捆绑中还是在外面消费服务?如何做到这一点?可能会出现什么问题?
我正在探索过去几周如何实施OSGI.我知道每个bundle都使用自己的类加载器来加载它的类.作为我调查的一部分,我理解每个bundle的类加载器的父级是null,即引导类加载器.
System.out.println("ClassInBundle class is loaded by "+ClassInBundle.class.getClassLoader());
System.out.println("ClassInBundle parent class is "+ClassInBundle.class.getClassLoader().getParent());
Run Code Online (Sandbox Code Playgroud)
bundle samplebundle中上面代码的输出是
ClassInBundle class is loaded by com.sample.bundle.samplebundle [34]
ClassInBundle parent class is null
Run Code Online (Sandbox Code Playgroud)
对于bundle中的导入,它维护一个packagename => classloader的映射,以便它可以将请求委托给正确的类加载器
Bundle SB = felix.getBundleContext().getBundle(0);
List<BundleWire> sbwires=SB.adapt(BundleWiring.class).getRequiredWires(null);
List<BundleWire> li=bundle.adapt(BundleWiring.class).getRequiredWires(null);
for(BundleWire i : li){
System.out.println(i);
}
Run Code Online (Sandbox Code Playgroud)
上面代码的输出是
[com.sample.bundle.samplebundle [34](R 34.0)] osgi.wiring.package; (osgi.wiring.package=com.test.packag) -> [org.apache.felix.framework [0](R 0)]
[com.sample.bundle.samplebundle [34](R 34.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework)(version>=1.8.0)(!(version>=2.0.0))) -> [org.apache.felix.framework [0](R 0)]
[com.sample.bundle.samplebundle [34](R 34.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.framework.wiring)(version>=1.2.0)(!(version>=2.0.0))) -> [org.apache.felix.framework [0](R 0)]
[com.sample.bundle.samplebundle [34](R 34.0)] osgi.ee; (&(osgi.ee=JavaSE)(version=1.6)) -> [org.apache.felix.framework [0](R …Run Code Online (Sandbox Code Playgroud) osgi dynamic-class-loaders equinox apache-felix embedded-osgi
我有兴趣在我的WAR中添加一个OSGI容器,但我找不到有关如何执行此操作的教程或文档.我找到了一些根本没用的东西.我对Felix实现和Atlassian实现很感兴趣.
我愿意这样做,以便我的战争接受插件,我可以动态扩展我的Web应用程序,并将其部署到任何Web服务器.
任何指向文档的链接?任何帮助表示赞赏.