4.10. Common Mistakes

It is surprisingly easy to trip up on the journey to your first working bundle. Some of the most common logistical and syntactical mistakes are summarized in this section. More complex programmatic and design issues are addressed in Chapter 6.

4.10.1. Activator

  • The activator must be defined as a public class because it is to be accessed by the framework. Do not make it package private.

  • The activator must have a public default no-arg constructor. Not defining any constructor is fine, because the default constructor will be automatically provided. However, if you explicitly define a constructor other than the no-arg constructor, no default constructor will be provided. This causes a failure when the framework tries to instantiate your activator.

4.10.2. Manifest

  • The Bundle-Activator manifest header must correctly point to the path to the class implementing the activator inside the bundle JAR file.

  • Check whether your manifest header definitions comply with the manifest specification (available at http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html). Starting from Java 2 SDK, the syntax is more strictly enforced:

    - The same header cannot be repeated in the manifest.

    - There cannot be an extra empty line before any header.

    - A line must not be longer than 72 bytes.

    - Use only a colon followed by a white space between the header and its value. Don't use TAB ( ).

    - Use only a white space (not TAB) at the beginning of a line to indicate continuation of the previous line.

    - There must be an extra new line at the end of the manifest.

4.10.3. Creating a JAR File

  • Make sure you have included the manifest definition when you package the JAR file using the jar command. You always need to use the command in the form of jar cmf Manifest bundle.jar contents, otherwise important OSGi headers are left out of the resultant JAR file.

  • Pack the JAR file so that the directory structure corresponds to the packages. For example, a bundle with the following layout won't work:

    META-INF/MANIFEST.MF
    /home/joe/project/com/acme/util/LinkedList.class
    /home/joe/project/com/acme/util/BTree.class
    

    because /home/joe/project is obviously not part of the package name.

  • You can include anything in the bundle JAR file, such as the original source files (.java files) and the manifest stub. Although these entries are ignored by the framework when the bundle is installed and activated, they can be handy if sources are needed for rebuilding the bundle.

  • When in doubt, you can unpack the bundle JAR file in a temporary directory, and examine whether META-INF/MANIFEST.MF indeed correctly contains the headers you intend to declare.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.86.18