title: How to access package via Package.getPackage(...)?
body: <p>In my current project I would like to store some configuration data in a package annotation and to access it by some CDI producers. If the annotation is not found in the current package the producers will search for it upward in the package hierarchy.</p>
  
  <p>So far so good. Unfortunately it seems so that I can access an existing package via <code>Package.getPackage("my.package")</code> only after the first access to one of its classes or interfaces.</p>
  
  <p>The following example illustrates this behaviour:</p>
  
  <p><strong>Class in package <code>a.b</code></strong></p>
  
  <pre><code>package a.b;
  
  public class ClassInMitte {
  }
  </code></pre>
  
  <p><strong>Example programm to access the package <code>oben.mitte</code></strong></p>
  
  <pre><code>package other;
  
  public class Refl {
      public static void main(String[] args)
      {
          Package viaName = Package.getPackage("a.b");
  
          System.out.println(viaName.getName());
          System.out.println(viaName.hashCode());
      }
  }
  </code></pre>
  
  <p>Running <code>Refl</code> results in a <code>NullPointerException</code>. <strong>But</strong> if I add <code>new ClassInMitte()</code> as first statement I can access the package information. Somehow I must access the content of a package before I can access the package information itself. This makes sense since otherwise the classloaders must scan the whole classpath while starting.</p>
  
  <p>But netherless is there an easy way to access package information without accessing the content of the package before? I know I could use frameworks like <a href="http://code.google.com/p/reflections/" rel="nofollow">reflections</a> but a 'lightweight' solution would be my prefered solution.</p>