gpt4 book ai didi

java - 在 JDK 11 中使用 OSGi 和 Apache Felix iPOJO

转载 作者:搜寻专家 更新时间:2023-10-31 20:31:42 27 4
gpt4 key购买 nike

我有一个围绕 OSGi 和 iPOJO 构建的项目,我正在尝试确定它是否仍适用于 JDK 11。它目前使用的是 JDK 8。自从最新版本的 iPOJO (1.12. 1) 于 2014 年发布。更新目标和 maven 编译器版本后,我遇到了以下问题:

[ERROR] Failed to execute goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle (default) on project redacted: Execution default of goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle failed. IllegalArgumentException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle (default) on project redacted: Execution default of goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.apache.felix:maven-ipojo-plugin:1.12.1:ipojo-bundle failed.
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
Caused by: java.lang.IllegalArgumentException
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.apache.felix.ipojo.manipulator.metadata.annotation.model.parser.AnnotationParser.read(AnnotationParser.java:32)
at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.MetaAnnotationBindingRegistry.createBindings(MetaAnnotationBindingRegistry.java:94)
at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.CompletableBindingRegistry.getBindings(CompletableBindingRegistry.java:45)
at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.CompletableBindingRegistry.getBindings(CompletableBindingRegistry.java:43)
at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.CompletableBindingRegistry.getBindings(CompletableBindingRegistry.java:43)
at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Selection.list(Selection.java:129)
at org.apache.felix.ipojo.manipulator.metadata.annotation.registry.Selection.get(Selection.java:98)
at org.apache.felix.ipojo.manipulator.metadata.annotation.MethodMetadataCollector.visitAnnotation(MethodMetadataCollector.java:69)
at org.objectweb.asm.ClassReader.b(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider.computeAnnotations(AnnotationMetadataProvider.java:111)
at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider.access$200(AnnotationMetadataProvider.java:44)
at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider$1.visit(AnnotationMetadataProvider.java:90)
at org.apache.felix.ipojo.manipulator.store.JarFileResourceStore.accept(JarFileResourceStore.java:161)
at org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider.getMetadatas(AnnotationMetadataProvider.java:75)
at org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider.getMetadatas(CompositeMetadataProvider.java:53)
at org.apache.felix.ipojo.manipulator.Pojoization.pojoization(Pojoization.java:360)
at org.apache.felix.ipojo.manipulator.Pojoization.pojoization(Pojoization.java:243)
at org.apache.felix.ipojo.plugin.ManipulatorMojo.execute(ManipulatorMojo.java:265)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more

粗略地看,maven-ipojo-plugin 的 asm 依赖似乎在 JDK 11 上有问题,这是有道理的,因为 iPOJO 对 asm 5.0.4 有传递依赖,而 JDK 11 支持不是添加到 asm 7.0。我试图排除传递依赖并添加 asm 7.0 作为依赖,但我仍然得到同样的错误。

感谢您的关注,如果有任何其他尝试或见解,我将不胜感激。

最佳答案

来自 ASMIllegalArgumentException在 Maven 构建期间指示插件正在使用的 ASM 库版本对于当前的 Java 字节码来说太旧了。 Java 11 字节码需要 ASM 7(如您所述),几周前才以稳定版本发布。

当从 JDK 9 迁移到 10 时,可以通过显式声明 ASM 6.2 为依赖项来解决这个问题,例如maven 阴影插件:

     <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<dependencies>
<!-- TODO: Remove for shade-plugin 3.1.2 - https://issues.apache.org/jira/browse/MSHADE-289 -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</plugin>

这个技巧对 JDK 11 不起作用,它需要更新插件本身,例如maven-shade-pluginmaven-plugin-plugin。正如您的努力所示,maven-ipojo-plugin 也是如此。如果该插件未得到维护,您可能应该考虑 ipojo-plugin 的替代方案以迁移到 Java 11。

您可以尝试将 maven-compiler-plugintarget 版本设置为 1.8,这应该会导致类文件与 ipojo 兼容-插入。但随后您可能还必须将 source 版本设置为 1.8,并且将无法使用任何 Java 9+ 语言功能。

关于java - 在 JDK 11 中使用 OSGi 和 Apache Felix iPOJO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53267586/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com