[英]OSGi: BND tools fail to @Reference only a specifc component
I have an OSGi component which looks like this我有一个看起来像这样的 OSGi 组件
@Activate
public MyComponent(@Reference OtherServiceA ref1, @Reference OtherServiceB ref2, @Reference OtherServiceC ref3) {
// remainder omitted
}
The @Reference
annotation does not appear anywhere else in the source. @Reference
注释不会出现在源中的其他任何地方。
I'm using gradle 5.6 with the BND tools to build the jar:我使用 gradle 5.6 和 BND 工具来构建 jar:
// file: build.gradle
plugins {
id 'biz.aQute.bnd.builder'
}
Running the jar task results in the following error:运行 jar 任务会导致以下错误:
> Task :my.pro.ject:jar FAILED
error : In component my.pro.ject.mypackage.MyComponent, @Reference cannot be used for method parameters
FAILURE: Build failed with an exception.
and the corresponding stack trace和相应的堆栈跟踪
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':my.pro.ject:jar'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:166)
[...]
Caused by: org.gradle.api.GradleException: Bundle my.pro.ject-2.0.0-SNAPSHOT.jar has errors
at aQute.bnd.gradle.BundleTaskConvention.failBuild(BundleTaskConvention.groovy:310)
at aQute.bnd.gradle.BundleTaskConvention$_buildBundle_closure6$_closure7.doCall(BundleTaskConvention.groovy:294)
at aQute.bnd.gradle.BundleTaskConvention$_buildBundle_closure6.doCall(BundleTaskConvention.groovy:200)
at org.gradle.util.ClosureBackedAction.execute(ClosureBackedAction.java:71)
[...]
I believe the error message is misleading: The following code works well:我认为错误消息具有误导性:以下代码运行良好:
@Activate
public MyComponent(@Reference OtherServiceA ref1, @Reference OtherServiceB ref2) { // just removed ref3
// remainder omitted
}
clean
--refresh-dependencies
, nothing workedclean
--refresh-dependencies
运行 gradle ,没有任何效果 Further details: - I'm using Java 1.8.151(32-bit)更多详细信息: - 我使用的是 Java 1.8.151(32 位)
You do not specify the version for the biz.aQute.bnd.builder
plugin.您没有指定
biz.aQute.bnd.builder
插件的版本。 The latest release is 5.0.1
which definitely has support for OSGi DS 1.4 annotations which support constructor injection.最新版本是
5.0.1
,它肯定支持支持构造函数注入的 OSGi DS 1.4 注释。
You also do not mention which version of the OSGi DS annotations you use.您也没有提到您使用的是哪个版本的 OSGi DS 注释。 You must use version 1.4 to use constructor injection.
您必须使用 1.4 版才能使用构造函数注入。
As for why it only fails on your machine, I cannot say :-(至于为什么它只在你的机器上失败,我不能说:-(
I ran into this same issue, but while using the bnd-maven-plugin (5.2.0) in a project built using a quite ancient Java 8 (1.8.0_60).我遇到了同样的问题,但是在使用非常古老的 Java 8 (1.8.0_60) 构建的项目中使用 bnd-maven-plugin (5.2.0) 时。 Updating either to something (more) recent (bnd-maven-plugin to 5.3.0 or java to 1.8.0_162) solved it for me.
更新到(更多)最近的东西(bnd-maven-plugin 到 5.3.0 或 java 到 1.8.0_162)为我解决了这个问题。
I had the debugger attached and noticed the error was produced while processing the @Deactivate annotated method.我连接了调试器,并注意到在处理 @Deactivate 注释方法时产生了错误。 I did not investigate further why the parameters from the constructor were evaluated as being part of the deactivate method, and why this problem disappears when updating the jdk.
我没有进一步调查为什么来自构造函数的参数被评估为 deactivate 方法的一部分,以及为什么在更新 jdk 时这个问题消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.