0 Replies Latest reply on May 28, 2009 8:07 AM by Arbi Sookazian

    using package-info.java in your Seam apps

    Arbi Sookazian Master

      I ran across package-info.java on pg. 190 of SiA book.


      Here is an example of this file, from org.jboss.seam.core package:


      /**
       * A set of Seam components that implement Seam.
       * This is where the magic happens.
       */
      @Namespace(value="http://jboss.com/products/seam/core", prefix="org.jboss.seam.core")
      @AutoCreate
      package org.jboss.seam.core;
      
      import org.jboss.seam.annotations.AutoCreate;
      import org.jboss.seam.annotations.Namespace;




      Annotations that can be applied to the package element are referred to as package-level annotations. An annotation with ElementType.PACKAGE as one of its targets is a package-level annotation. Package-level annotations are placed in a package-info.java file. This file should contain only the package statement, preceded by annotations. When the compiler encounters package-info.java file, it will create a synthetic interface, package-name.package-info. The interface is called synthetic because it is introduced by the compiler and does not have a corresponding construct in the source code. This synthetic interface makes it possible to access package-level annotations at runtime.

      source: My Link


      Is it considered good/bad practice to use package-info.java in our Seam apps?  What are the adv/disadv of using this file per package?


      For example, let's say you wanted all classes in a particular package to have @AutoCreate; can you use package-info.java to annotate at the package level rather than annotating multiple classes in that package?  Must you have @Namespace as well?


      The Seam core packages all have them apparently, but really the underlying reason there is to establish a link b/n an XML namespace and a Java package in the context of the component descriptor...


      btw, what spec or Java SE version did this package-info.java originate from?