Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I make the manifest available during a Maven/Surefire unittest run "mvn test"?
    text
    copied!<p>How do I make the manifest available during a Maven/Surefire unittest run "mvn test" ?</p> <p>I have an open-source project that I am converting from Ant to Maven, including its unit tests. Here's the project source repository with the Maven project: <a href="http://github.com/znerd/logdoc" rel="noreferrer">http://github.com/znerd/logdoc</a></p> <p>My question pertains to the primary module, called "base". This module has a unit test that tests the behaviour of the static method <code>getVersion()</code> in the class <code>org.znerd.logdoc.Library</code>. This method returns:</p> <pre><code>Library.class.getPackage().getImplementationVersion() </code></pre> <p>The <code>getImplementationVersion()</code> method returns a value of a setting in the manifest file. So far, so good. I have tested this in the past and it works well, as long as the manifest is indeed available on the classpath at the path <code>META-INF/MANIFEST.MF</code> (either on the file system or inside a JAR file).</p> <p>Now my challenge is that the manifest file is not available when I run the unit tests:</p> <pre><code>mvn test </code></pre> <p>Surefire runs the unit tests, but my unit test fails with a mesage indicating that <code>Library.getVersion()</code> returned <code>null</code>.</p> <p>When I want to check the JAR, I find that it has not even been generated. Maven/Surefire runs the unit tests against the classes, <em>before</em> the resources are added to the classpath.</p> <p>Further investigation shows Surefire generates its own JAR file in a temporary directory, e.g.</p> <pre><code>/private/var/folders/TR/TREvj1wIHYyAcUy-xmc3UU+++TI/-Tmp-/surefirebooter7448562488934426857.jar </code></pre> <p>And then uses this JAR to load the Library class. This JAR does not contain the resources I stuck under <code>src/main/resources</code>. So putting a <code>META-INF/MANIFEST.MF</code> file also does not work.</p> <p>So how do I tell Surefire to have my <code>META-INF/MANIFEST.MF</code> file available from the same class loader as the <code>Library</code> class.</p> <blockquote> <p>Note that I use Maven 2.2.0, Java 1.6.0_17 on Mac OS X 10.6.2, with JUnit 4.8.1.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload