我在我的应用程序中使用嵌入式Felix.应用程序可能会处理暴露类似接口的大量插件IFoo.默认情况下,实现FooImpl希望大多数插件默认FooImpl可以与特定配置文件一起使用.
我希望FooImpl在出现新配置文件时动态安装并启动相同的bundle(with ).我已经审查过FileInstall,但不知道如何在那里应用它.
更新:部署顺序.jar包含FooImpl且IFoo稳定,但我需要热部署新的实例,这些实例是将新的.cfg文件上传到FileInstall的范围.所以非常简单 - 用户上传.cfg,新服务(实例FooImpl)出现了.
在OSGI中,我们可以在运行时更新,激活,停用软件包.
但我不明白它是如何可能的,因为其他一些人可能会使用这个包的功能.为什么不发生这种情况会导致应用程序崩溃?
通常,在JVM中,无论何时运行任何应用程序,它都会加载源类文件和所需的Java API类文件并生成结果.
你能解释一下OSGI的基本架构是什么,以便它能够实现上述目标.
我开发了一个基于JavaFX和OSGi Felix容器的丰富应用程序.当我的JavaFX是开始,一个org.osgi.framework.BundleException被抛出,表明framwork无法电线我的JavaFX包:
ERROR: Bundle app-impl-bundle [3] Error starting eclipse-project:T:\workspace\fast-osgi\app-impl-bundle\ (org.osgi.framework.BundleException: Unresolved constraint in bundle app-impl-bundle [3]: Unable to resolve 3.0: missing requirement [3.0] osgi.wiring.package; (&(osgi.wiring.package=javafx.stage)(version>=2.2.0)))
Run Code Online (Sandbox Code Playgroud)
这是我的MANIFEST.MF文件:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: app-impl-bundle
Bundle-SymbolicName: app-impl-bundle
Bundle-Version: 1.0.0.qualifier
Require-Bundle: app-bundle;bundle-version="0.0.1"
Bundle-Activator: com.mycompany.app.impl.Activator
Import-Package: javafx.stage;version="2.2.0",
javax.xml.parsers,
org.osgi.framework;version="1.8.0",
org.w3c.dom,
org.xml.sax
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .,
target/lib/log4j-1.2.17.jar
Run Code Online (Sandbox Code Playgroud)
这里用于启动OSGi框架的VM Arguments(我使用此插件在Eclipse Luna下运行我的项目):
-Dosgi.requiredJavaVersion=1.8 -Dorg.osgi.framework.bundle.parent=ext
Run Code Online (Sandbox Code Playgroud)
最后一个参数无效.尽管如此,这篇文章告诉它它可以在Equinox上运行......
我找到了一个将此选项添加到VM参数的解决方案:
-Dorg.osgi.framework.system.packages.extra=javafx.stage
Run Code Online (Sandbox Code Playgroud)
但这不是很灵活.
您认为Felix OSGi的实现是否存在问题?它应该只与Equinox一起使用吗?有人可以帮帮我吗?这是正确的方法吗?
我创建了一个依赖于 SLF4J 的包,因此我使用 Logback 来实现 OSGI。这一切都捆绑起来并安装正常,但是当我开始捆绑时,出现以下异常:
org.osgi.framework.BundleException:无法解析 com.felix.test [20](R 20.0):缺少要求 [com.felix.test [20](R 20.0)] osgi.wiring.package;(osgi.wiring.package=groovy.lang) 未解决的需求:[[com.felix.test [20](R 20.0)] osgi.wiring.package; (osgi.wiring.package=groovy.lang)]
我可以看到我的清单文件中groovy.lang列出了Import-Package,我很确定问题是 Logback 已被嵌入,但它的引用都没有。
我用来创建捆绑包,这是配置:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
*
</Import-Package>
<Embed-Dependency>
*
</Embed-Dependency>
<Embed-Directory>
osgi-inf/libs
</Embed-Directory>
<Embed-Transitive>
true
</Embed-Transitive>
</instructions>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这是我的清单:
Manifest-Version: 1.0
Bnd-LastModified: 1436982944102
Build-Jdk: 1.8.0_45
Built-By: tim.clifford
Bundle-ClassPath: .,osgi-inf/libs/org.osgi.core-1.0.0.jar,osgi-inf/libs/
servlet-api-2.5.jar,osgi-inf/libs/org.apache.felix.scr.annotations-1.9.
6.jar,osgi-inf/libs/httpclient-osgi-4.5.jar,osgi-inf/libs/httpclient-4.
5.jar,osgi-inf/libs/httpcore-4.4.1.jar,osgi-inf/libs/commons-logging-1.
2.jar,osgi-inf/libs/commons-codec-1.9.jar,osgi-inf/libs/httpmime-4.5.ja
r,osgi-inf/libs/httpclient-cache-4.5.jar,osgi-inf/libs/fluent-hc-4.5.ja
r,osgi-inf/libs/ehcache-2.10.0.jar,osgi-inf/libs/slf4j-api-1.7.7.jar,os
gi-inf/libs/commons-lang3-3.4.jar,osgi-inf/libs/logback-classic-1.1.3.j
ar,osgi-inf/libs/logback-core-1.1.3.jar
Bundle-ManifestVersion: 2
Bundle-Name: com.felix.test
Bundle-SymbolicName: com.felix.test
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Felix实现的OSGi HTTP服务启动Wicket应用程序,因为我只是使用WicketServletwith applicationClassName参数注册服务:
props.put("applicationClassName", MainApplication.class.getName());
service = (HttpService)context.getService(httpReference);
service.registerServlet("/", new WicketServlet(), props, null);
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用Felix Whiteboard实现并将Web服务注册为Servlet一个:
props.put("alias", "/");
props.put("init.applicationClassName", MainApplication.class.getName());
registration = context.registerService(Servlet.class.getName(), new WicketServlet(), props);
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,当我使用Pax Runner和Felix(mvn package install pax:run -Dframework=felix -Dprofiles=log,config)部署它时失败,异常似乎与以下内容有关ClassLoader:
[Jetty HTTP Service] ERROR org.apache.felix.http.whiteboard - Failed to register servlet
org.apache.wicket.WicketRuntimeException: Unable to create application of class es.warp.sample.HTTPLocalGUI.MainApplication
....
....
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
....
....
Run Code Online (Sandbox Code Playgroud)
我试图导出捆绑中的所有内容,它也是如此.
最奇怪的是,如果我使用Equinox(mvn package install pax:run -Dframework=felix -Dprofiles=log,config …
我不太了解最新的Apache Felix版本(4.0.2)的OSGi版本.
我已经读过Apache Felix 4符合OSGi 4.3,我认为这意味着Felix框架包将导出org.osgi.framework版本1.6.0.
它没有,快速查看Felix的清单说它出口版本1.5.0,所以(至少)其中一个假设是错误的.如果我检查Equinox 3.7,我确实看到了org.osgi.framework版本1.6.0的导出
谁能指出我正确的方向?
我正在研究JavaFX 2.2和Java 8的示例.我创建了这个简单的Apache Felix Activator:
激活:
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator
{
Stage stage;
@Override
public void start(BundleContext context) throws Exception
{
Platform.runLater(new Runnable()
{
@Override
public void run()
{
stage = new Stage();
BorderPane pane = new BorderPane();
Scene scene = new Scene(pane, 400, 200);
pane.setCenter(new Label("This is a JavaFX Scene in a Stage"));
stage.setScene(scene);
stage.show();
}
});
System.out.println("Main Module is loaded!");
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 在一个OSGi ServiceTracker中使用OSGi的最佳做法是BundleActivator什么?我在Web上看到了在start方法中打开跟踪器的示例,将其存储在实例变量中,并在stop方法中关闭它,使其在捆绑的生命周期中保持打开状态.这个合适吗?我一直在编写代码,只要我需要它就打开跟踪器,获取服务并使用它,然后关闭跟踪器.当然,BundleContext如果我想在以后使用它,则需要将自身存储在实例变量中.因为我必须存储一个或另一个,所以我存储的差别可能不大.
在一个相关的问题中,如果我每次需要时都打开跟踪器,是否有必要在我使用我从中获得的服务时保持打开状态,或者我可以打开跟踪器,获取服务,关闭跟踪器,然后使用该服务?在使用该服务之前,我认为没有理由不能关闭跟踪器.
我是OSGi的新手.我在Jboss AS 7.1中使用Apache felix for OSGi容器.在访问"localhost:8090/system/console"时,我可以找到已安装的软件包列表.当我检查一个bundle的导入包时,我发现很少从system.bundle导入.
来自system.bundle的导入包javax.activation,version = 0.0.0 (0)
我的问题是,system.bundle是什么意思?从哪里装货?
我正在尝试扩展OSGI服务.正在扩展的OSGI服务包括一些引用和属性.我正在使用新org.osgi.service.component.annotations包装.由OSGi R6实现的注释处理器生成的元XML不考虑我正在扩展的OSGI服务中的引用和属性声明.
Apache Felix Maven SCR插件很好地处理了这个用例,并且用Felix注释注释的类也包括基类的引用和属性.
有没有办法让这个工作与官方OSGI注释实现.我不想回退到Felix SCR插件,除非我必须像他们的官方网站所说继续进行OSGI实现,这是一个尚未使用SCR插件的新项目.
apache-felix ×10
osgi ×10
java ×4
javafx ×2
maven ×2
aem ×1
bndtools ×1
eclipse ×1
equinox ×1
httpservice ×1
java-8 ×1
javafx-2 ×1
jboss7.x ×1
osgi-bundle ×1
wicket ×1