2

我正在使用插件 org.eclipse.virgo.bundlor 从模板创建 OSGi 清单文件。当我使用 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>
4

2 回答 2

1

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

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

bnd 项目包含一个名为bnd-maven-plugin. 这里有一个使用它的示例项目,它可以很容易地添加到您的 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 生成的清单,您还需要告诉 maven-jar-plugin 将其拉入。通常您会将类似这样的内容添加到父 pom:

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

从名为 bnd.bnd的bnd-maven-plugin文件中提取配置,其文档可在此处获得

另一个基于 bnd 的工具称为 maven-bundle-plugin,由 Apache Felix 托管。该文档在此处可见,并告诉您如何配置 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 提交者),但两者都可能适合你。

于 2015-08-14T16:23:48.960 回答
1

问题是 bundler 的版本使用了旧版本的 ASM,它不理解 Java 8 类文件。因此,您要么需要更新到 bundlor,要么更改为使用其他工具。bnd已更新以支持 Java 8 类文件。

于 2015-08-14T09:50:06.433 回答