gpt4 book ai didi

java - Bundlor 无法与 Java 8 lambda 一起正常工作

转载 作者:行者123 更新时间:2023-11-30 08:48:22 25 4
gpt4 key购买 nike

我正在使用插件 org.eclipse.virgo.bundlor 从模板创建 OSGi list 文件。当我使用 lambdas 时,插件无法正常工作。您能否建议更改我的 maven 文件或替代 bundlor 以允许我使用 lambda?

这是我的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lamba</groupId>
<artifactId>lamba</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lamba</name>
<properties>
<java-source-version>1.8</java-source-version>
<java-target-version>1.8</java-target-version>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.eclipse.virgo.bundlor</groupId>
<artifactId>org.eclipse.virgo.bundlor.maven</artifactId>
<version>1.1.2.RELEASE</version>
<dependencies>
<dependency>
<groupId>org.eclipse.virgo.bundlor</groupId>
<artifactId>org.eclipse.virgo.bundlor</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.eclipse.virgo.bundlor</groupId>
<artifactId>org.eclipse.virgo.bundlor.blint</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>

</dependencies>


<executions>
<execution>
<id>${project.artifactId}-bundle-manifest</id>
<phase>prepare-package</phase>
<goals>
<goal>bundlor</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java-source-version}</source>
<target>${java-target-version}</target>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

导致问题的代码很简单:

package lamba.internal;

import java.util.function.Supplier;

/**
*
*/
public class HiImpl {
public Supplier<String> p=()->"hi";

}

我的错误是:

[INFO] --- org.eclipse.virgo.bundlor.maven:1.1.2.RELEASE:bundlor (lamba-bundle-manifest) @ lamba ---
java.lang.ArrayIndexOutOfBoundsException: 28712
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.objectweb.asm.ClassReader.<init>(Unknown Source)
at org.eclipse.virgo.bundlor.support.asm.AsmTypeArtifactAnalyzer.analyse(AsmTypeArtifactAnalyzer.java:37)
at org.eclipse.virgo.bundlor.support.StandardManifestGenerator.analyzeEntry(StandardManifestGenerator.java:114)
at org.eclipse.virgo.bundlor.support.StandardManifestGenerator.analyzeEntries(StandardManifestGenerator.java:99)
at org.eclipse.virgo.bundlor.support.StandardManifestGenerator.generate(StandardManifestGenerator.java:64)
at org.eclipse.virgo.bundlor.maven.plugin.internal.MavenBundlorExecutor.execute(MavenBundlorExecutor.java:68)
at org.eclipse.virgo.bundlor.maven.plugin.BundlorMojo.execute(BundlorMojo.java:222)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
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:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
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)
Manifest written to '/Users/me/proj/lamba/target/classes/META-INF/MANIFEST.MF'

更新,我尝试使用较新版本的 ASM 库,但没有用:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lamba</groupId>
<artifactId>lamba</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>lamba</name>
<properties>
<java-source-version>1.8</java-source-version>
<java-target-version>1.8</java-target-version>
</properties>

<build>
<finalName>${project.artifactId}</finalName>

<plugins>
<plugin>
<groupId>org.eclipse.virgo.bundlor</groupId>
<artifactId>org.eclipse.virgo.bundlor.maven</artifactId>
<version>1.1.2.RELEASE</version>

<dependencies>
<dependency>
<groupId>org.eclipse.virgo.bundlor</groupId>
<artifactId>org.eclipse.virgo.bundlor</artifactId>
<version>1.1.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm.tree</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm.commons</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.virgo.bundlor</groupId>
<artifactId>org.eclipse.virgo.bundlor.blint</artifactId>
<version>1.1.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm.tree</artifactId>
</exclusion>
<exclusion>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm.commons</artifactId>
</exclusion>
</exclusions>
</dependency>


<dependency>
<groupId>org.objectweb.asm</groupId>
<artifactId>com.springsource.org.objectweb.asm.commons</artifactId>
<version>3.2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>


<executions>
<execution>
<id>${project.artifactId}-bundle-manifest</id>
<phase>prepare-package</phase>
<goals>
<goal>bundlor</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java-source-version}</source>
<target>${java-target-version}</target>
<skip>false</skip>
</configuration>
</plugin>
</plugins>

</build>




</project>

最佳答案

据我所知,bundlor 插件不再更新,因此不太可能增强以理解 Java 8 字节码。

基于名为 bnd 的工具,有两个主要的替代方案可用,许多 OSGi 项目都在使用该工具。

bnd 项目托管一个名为 bnd-maven-plugin 的插件。有一个使用它的示例项目 here ,它可以很容易地添加到您的 pom 中,如下所示:

<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>2.4.1</version>

<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>

请注意,为了获取 bnd 生成的 list ,您还需要告诉 maven-jar-plugin 将其拉入。通常您会向父 pom 添加如下内容:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<useDefaultManifestFile>true</useDefaultManifestFile>
</configuration>
</plugin>

bnd-maven-plugin 从名为 bnd.bnd 的文件中提取配置,其文档可用 here

另一个基于 bnd 的工具称为 maven-bundle-plugin,由 Apache Felix 托管。文档可见here , 并告诉你如何配置 pom.

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.foo.myproject.api</Export-Package>
<Private-Package>org.foo.myproject.*</Private-Package>
<Bundle-Activator>org.foo.myproject.impl1.Activator</Bundle-Activator>
</instructions>
</configuration>
</plugin>

如您所见,maven-bundle-plugin 要求您将模块的打包类型更改为 bundle 或延长默认生命周期,以便它可以正确打包。因此,它并不总是能很好地与其他基于 maven 的工具一起使用。虽然它被广泛使用。

我个人更喜欢 bnd-maven-plugin(我是 bnd/bndtools 提交者),但两者可能都适合您。

关于java - Bundlor 无法与 Java 8 lambda 一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31997681/

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