Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

Visibility of plain jar in tycho-surefire-plugin

The problem

I am faced with the following scenario:

The sources of an Eclipse test plugin (tycho packaging type eclipse-test-plugin) depend on a "plain" jar (read: non-OSGi jar). I managed to get the tests to compile and run in Eclipse, however when running Maven/Tycho from the command line, tycho-surefire-plugin fails to execute the tests because the jar is not visible at test time. This results in a java.lang.NoClassDefFoundError while attempting to load a class from the jar.

Looking at mvn -e -X output does not reveal anything significant.

My question is, how can I include the jar in the classpath of tycho-surefire-plugin when running Maven/Tycho from the command line?

Attempts

Here is everything I have tried so far:

  1. Use <extraRequirements> as per the tycho-surefire-plugin documentation. This however fails because the jar's packaging type is jar, while <extraRequirements> expects one of the eclipse-xxx packaging types.

For a good measure I also tried

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

but the packaging type is still considered to be jar.

  1. Use <argLine> as per tycho-surefire-plugin documentation:
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
  <argLine>-cp path-to-the-jar</argLine>
</configuration>

however this appears to have no effect as the java.lang.NoClassDefFoundError persists.

  1. Include the jar in the Eclipse test plugin. The jar is present in the MANIFEST.MF
Bundle-ClassPath: the.jar

in the build.properties

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

and in the .classpath (although this doesn't matter for tycho-surefire-plugin).

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

tycho-surefire-plugin once again reports java.lang.NoClassDefFoundError.

  1. Create a dedicated Eclipse plugin to house the jar. This is for the most part equivalent to 3, where the Eclipse test plugin simply depends on this new dedicated Eclipse plugin. The java.lang.NoClassDefFoundError still rears its head.

  2. Transition to Tycho 2.x.x since it supports the Directory location type. Unfortunately it is not possible to include the jar in the target definition because its packaging type is jar.

question from:https://stackoverflow.com/questions/65836051/visibility-of-plain-jar-in-tycho-surefire-plugin

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...