- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,感谢您的阅读,
我当前在将多个资源安装到我的 OSGi 框架中时遇到问题。我正在使用带有 Bndtools 插件的 Eclipse IDE。
我有一个在线 OSGi 存储库,遵循 RFC 112 。我已经成功编写了一个方法,可以将所有这些资源解析为 List<Resource>
。现在,我可以通过使用列表的 .get(int) 方法来获取资源。
我写了一个方法,可以直接将资源安装到框架中,代码如下:
public void installResource(Resource res) {
RepositoryContent myRepoContext = (RepositoryContent) res;
InputStream myInputStream = myRepoContext.getContent();
try {
installBundle(myInputStream);
System.out.println("Installation of " + res.toString() + " SUCCESSFUL.");
} catch (Exception e) {
System.out.println("Installation of " + res.toString() + " FAILED.");
e.printStackTrace();
}
这是使用 installBundle(InputStream inputstream
我写的方法如下:
public void installBundle(InputStream inputStream) {
Bundle bundle = null;
try {
bundle = context.installBundle(null, inputStream);
System.out.println("Context installed bundle correctly");
} catch (BundleException e) {
System.out.println("Context could not install bundle correctly.");
e.printStackTrace();
}
}
现在我想做的是将多个资源安装到我的框架中。我不希望它们出现在 RESOLVED
中状态,只是 INSTALLED
状态就够了。
当我尝试安装 1 个资源时,一切正常:
installResource(resource1);
这工作正常,因为如果我随后使用 lb
请求框架中当前安装的 bundle /资源命令在 shell 中,我可以看到该包位于 INSTALLED
中状态:
13|Installed | 1|org.dyamand.test.serialization (0.13.15)|0.13.15
到目前为止一切顺利,资源的安装方法正在运行。虽然我想。当我尝试安装另一个资源时,出现了问题。我没有收到任何错误消息或异常。相反,我看到我自己打印出类似 Installation of " + res.toString() + " SUCCESSFUL."
的消息。 。这应该意味着资源已正确安装,因为没有错误或没有返回任何内容。
但是当我使用 lb
再次检查 bundle 时,第二个资源/包不存在。第一个是。已使用许多不同的资源尝试过此操作(有些资源处于 INSTALLED
状态,有些资源处于 RESOLVED
状态)。 它从来没有工作过,只是安装了第一个资源。
例如,如果我停止框架并使用以下代码再次启动它:
installResource(resource1);
installResource(resource2);
唯一发生的事情是资源1开始安装。
RESOLVED
中,则可能无法安装第二个资源或ACTIVE
状态?我一开始也是这么想的,但事实证明这是错误的。我没有直接从 OSGi 存储库中获取的资源进行安装,而是访问 Maven Central 并获得了 3 个随机包及其直接 URL。可以在下面的代码中找到 URL 以及如何调用该方法进行安装。再次使用installBundle方法:
installBundle("https://search.maven.org/remotecontent?filepath=org/osgi/org.osgi/3.0.0/org.osgi-3.0.0.jar");
installBundle("https://search.maven.org/remotecontent?filepath=org/osgi/enroute/examples/microservice/rest-app-jpa/0.0.1/rest-app-jpa-0.0.1.jar");
installBundle("https://search.maven.org/remotecontent?filepath=org/coindirect/api/1.0.1/api-1.0.1.jar");
当像这样启动框架,然后使用 lb
请求 bundle 时,所有 3 个都出现在 INSTALLED
中状态。请参阅lb
输出如下:
13|Installed | 1|osgi (3.0.0)|3.0.0
14|Installed | 1|rest-app-jpa (0.0.1)|0.0.1
15|Installed | 1|https://search.maven.org/remotecontent?filepath=org/coindirect/api/1.0.1/api-1.0.1.jar (0.0.0)|0.0.0
我一直在互联网上搜索为什么会发生这种情况的解释,所以我向大家提出问题:有人知道为什么我不能直接在框架中安装多个资源吗?
我不明白直接从 URL 安装与直接从资源安装有什么不同,因为它们都可以工作(至少第一次)。有人已经说过,我可以从他们的直接 URL 链接安装所有包,是的,这可以工作,但是:我没有从存储库中取出的资源的直接 URL 链接。我只能访问Capability
具有命名空间 osgi.content
就像我的方法获取InputStream
一样以便可以安装资源。
非常感谢您的帮助。谢谢!
最佳答案
我假设context.installBundle(null, inputStream)
指的是this method 。如果是这样,您将传递 null
作为包的 location
。 The specs没有明确说明如果 location
为 null
会发生什么,但他们确实说了
Every bundle is uniquely identified by its location string. If an installed bundle is using the specified location, the installBundle methods must return the Bundle object for that installed bundle and not install a new bundle.
所以我的猜测是 null
是(或以某种方式成为)有效的 location
,然后第一次尝试之后的每次尝试都尝试使用相同的 location
根据规范,它不会安装该 bundle 。
关于java - OSGi:无法直接从存储库安装超过 1 个资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57510246/
我在 trying to share the Struts packages 时遇到了这个问题在 OSGi 容器内的多个包之间。我想避免在包内重复依赖项并在它们之间引入新的依赖项(通过让一个包导出其内
我正在考虑在我们的项目中管理版本控制的最佳方式。目前,我们 bundle 中的每个包都是导出的(这将在以后改进,所以不要因为这个失礼而挂断电话)。我们正在使用 maven-bundle-plugin,
我正在进行一个项目,我们将迁移基于大量定制技术的主要软件系统,使其基于 OSGi 服务。为此,我们可能需要某种与 OSGi 服务配合良好的消息总线。 同步和异步传送 仅点对点 保证交付 - 最好通过文
我的项目有一组自定义定义的注释,它们可以出现在 OSGi 4.3 框架中部署的任何包中。我想在类路径中找到任何带有这些注释的类。我尝试使用 BundleWiring.listResources(...
我创建了一个片段包来访问一些添加到第二方 jar 的功能。我的片段应该注册一个服务来公开这个新功能。它似乎不起作用。在我深入进行故障排除之前,我想知道这是否被允许?也就是说,Felix SCR 的 b
OSGi 是 Java 的动态模块化系统。好的,但是基线主题是什么,为什么要开发 OSGi?使用 OSGi 有什么好处?开发 OSGi 的主要故事是什么?它为什么存在? 最佳答案 如果你仔细观察,Ja
当一个包被更新(比如修复一个错误)时,当前正在使用正在更新的包的其他包会发生什么? 假设有两个捆绑包 service 和 dao。假设当我发出更新 dao 层的命令时,服务包中的类正在使用 dao 包
在 OSGi 下,组件与服务之间的主要区别是什么?据我了解,所有服务都必须是组件,但并非所有组件都必须是服务。 在示例用例中使用其中一种比另一种有什么好处? 最佳答案 “组件”的定义不如服务正式。 服
这合法吗?org.fragment1 的 MANIFEST.MF(org.host 是普通包,不是片段): Bundle-SymbolicName: org.fragment1 Fragment-Ho
在我当前的应用程序中,我在几个地方遇到了这种模式:我在一个 bundle 中有两个服务接口(interface),它们执行不同但相关的工作。 interface Service1 { ... } in
我的 OSGi 应用程序需要一个 jar(sample;version=A),并且我必须将相同的 jar(sample;version=B) 用于我开发的新包。 示例 jar 有一些增强功能,因此我不
osgi> install file:D:\f1\*.jar osgi> install --start file:D:\f1\*.jar 以上命令在 WSO2 OSGi 控制台中是非法的。如何从文件
和有什么不一样和 在spring DM的xml配置文件中。 最佳答案 可用于获取 对现有 OSGi 服务的引用,以便您的 bean 可以使用它。 可用于导出将 bean 作为 OSGi 服务,以
我有一个应用程序暂时使用 Equinox 作为 osgi 框架。直到现在我都使用系统属性 osgi.install.area 来指定我的包在哪里 ${osgi.install.area}/ plu
背景 在过去一年左右的时间里,我设计了许多工具,旨在帮助我为 XPage 编程。这些工具主要包括帮助程序 java 类、扩展日志记录(使用 OpenLogger 和我自己的东西),以及我个人觉得我不能
我有一个 OSGi 组件 MyComponent . 该组件引用了服务 MyService .现在MyService有几个实现 MyServiceImpl1和 MyServiceImpl2 . MyC
我有几个 OSGi 包,每个都可以从 OSGi 包存储库更新。 当我启动我的 OSGi 框架 (Apache Felix) 时,我希望第一个包启动并检查所有已安装包的更新。如果有可用更新,它应该更新每
当我们在 Apache Felix Web OSGi 控制台的配置选项卡中更新组件的任何配置时,这些配置设置保存在哪里?这是针对 AEM 6.0 或更高版本。 最佳答案 手动保存的配置设置存储在 cr
我有简单的 OSGI 事件监听器类 @Component(immediate = true) @Service(value = { EventHandler.class, JobConsumer.cl
我们正在开发一个网络应用程序(我们称之为图像库),我们已经确定了以下需求: 该应用程序迎合由一组用户组成的客户。 可以动态创建新客户并由客户管理其用户 客户有不同的功能集,可以动态更改 客户可以开发自
我是一名优秀的程序员,十分优秀!