title: How to get package version at running Tomcat?
body: <p>How to get package version at running Tomcat?</p>
  
  <p>I try getClass().getPackage().getImplementationVersion() but this always returns <code>null</code>.
  I guess it is because my war wasn't yet packaged and Tomcat executes .classes (aka exploded war).
  <code>META-INF\MANIFEST.MF</code> is present in final war, but not in <code>target\&lt;project.name&gt;\META-INF</code> folder</p>
  
  <blockquote>
    <p><a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Package.html" rel="nofollow noreferrer">java.lang.Package</a></p>
    
    <p>Package objects contain version information about the implementation
    and specification of a Java package. This versioning information is
    retrieved and made available by the ClassLoader instance that loaded
    the class(es). Typically, it is stored in the manifest that is
    distributed with the classes.</p>
  </blockquote>
  
  <p>Related is <a href="https://stackoverflow.com/questions/2712970/how-to-get-maven-artifact-version-at-runtime">Get Maven artifact version at runtime</a></p>
  
  <p>UPDATE. Before I have already added configuration for war build. But when running Tomcat from Eclipse, I get <code>null</code>.</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
      &lt;version&gt;2.1&lt;/version&gt;
      &lt;configuration&gt;
          &lt;archive&gt;                   
              &lt;manifest&gt;
                  &lt;addDefaultImplementationEntries&gt;true&lt;/addDefaultImplementationEntries&gt;
                  &lt;addDefaultSpecificationEntries&gt;true&lt;/addDefaultSpecificationEntries&gt;
              &lt;/manifest&gt;
          &lt;/archive&gt;
          &lt;!-- this actually moves classes from \WEB-INF\classes to new jar 
          &lt;archiveClasses&gt;true&lt;/archiveClasses&gt;
          --&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>