title: Reading My Own Jar's Manifest Take 2
body: <p>This is in response to the <a href="https://stackoverflow.com/a/1273196/811299">near-universally accepted answer</a> to an <a href="https://stackoverflow.com/questions/1272648/reading-my-own-jars-manifest">old question</a>.  Since the answer is rather old (2009) and since it isn't working for me, I thought I'd ask to see if anyone knows why.</p>
  
  <p>My use case is developing a gradle plugin for internal use.  Whenever the plugin is applied, I'd dearly like to be able to print what version of my plugin is being used.  So I write the version into the plugin's manifest when the plugin is being built and attempt to read it back from the manifest when the plugin is applied, using the technique in the linked answer.</p>
  
  <p>I wrote up some code along the lines of the answer but it's not working.  I added a bunch of debugging code, and I can see that the code first finds the Manifest provided by the JDK itself:</p>
  
  <pre><code>Manifest-Version: 1.0
  Created-By: 1.7.0_07 (Oracle Corporation)
  </code></pre>
  
  <p>Then it finds my manifest, the one I am looking for, but throws a FileNotFoundException:</p>
  
  <p>java.io.FileNotFoundException: JAR entry META-INF/MANIFEST.MF not found in {path to my plugin jar in my local maven repository}.  How could  </p>
  
  <pre><code>        Enumeration&lt;URL&gt; resources = getClass().getClassLoader()
                  .getResources("META-INF/MANIFEST.MF");
  </code></pre>
  
  <p>find the manifest and then throw a FileNotFoundException when trying to read it with: </p>
  
  <pre><code>Manifest manifest = new Manifest(resources.nextElement().openStream());
  </code></pre>
  
  <p>This is the line where the exception is thrown.</p>
  
  <p>Can someone explain this odd behavior or come up with another, perhaps newer way of reading the manifest?</p>
  
  <p>This is running under Eclipse, in Windows, by the way.  Haven't tried it yet on Linux, where it might actually work, but I'd like it to work in both cases.</p>