2

问题

我面临以下情况:

Eclipse 测试插件(tycho 封装类型eclipse-test-plugin)的来源依赖于“普通”jar(阅读:非 OSGi jar)。我设法让测试在 Eclipse 中编译和运行,但是当从命令行运行 Maven/Tycho 时,tycho-surefire-plugin 无法执行测试,因为 jar 在测试时不可见。这会导致java.lang.NoClassDefFoundError尝试从 jar 加载一个类。

查看mvn -e -X输出并没有发现任何重要的东西。

我的问题是,从命令行运行 Maven/Tycho 时,如何将 jar 包含在 tycho-surefire-plugin 的类路径中?

尝试

这是我到目前为止所尝试的一切:

  1. <extraRequirements>按照 tycho-surefire-plugin文档使用。然而,这失败了,因为 jar 的包装类型是jar,而<extraRequirements>期望eclipse-xxx 包装类型之一。

为了一个好的措施,我也尝试过

<configuration>
  <dependencies>
    <dependency>
      <groupId>. . .</groupId>
      <artifactId>. . .</artifactId>
      <version>. . .</version>
      <scope>system</scope>
      <systemPath>path-to-the-jar</systemPath>
    </dependency>
  </dependencies>
</configuration>

但包装类型还是算的jar

  1. <argLine>按照 tycho-surefire-plugin文档使用:
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
  <argLine>-cp path-to-the-jar</argLine>
</configuration>

然而,这似乎没有效果,因为java.lang.NoClassDefFoundError持续存在。

  1. 将 jar 包含在 Eclipse 测试插件中。罐子存在于MANIFEST.MF
Bundle-ClassPath: the.jar

在里面build.properties

bin.includes = META-INF/,\
               the.jar

并且在.classpath(尽管这对 tycho-surefire-plugin 无关紧要)。

<classpathentry exported="true" kind="lib" path="the.jar"/>

tycho-surefire-plugin 再次报告java.lang.NoClassDefFoundError.

  1. 创建一个专用的 Eclipse 插件来存放 jar。这在很大程度上相当于 3,其中 Eclipse 测试插件仅依赖于这个新的专用 Eclipse 插件。java.lang.NoClassDefFoundError仍然抬起头来。

  2. 过渡到第谷 2.xx,因为它支持Directory位置类型。不幸的是,不可能将 jar 包含在目标定义中,因为它的包装类型是jar.

4

0 回答 0