Time for action - installing json

I could not find a version with OSGi headers for the remaining dependency, json. Maybe they'll be added by the time you cast your eyes on this (a little research before the selection of the dependency to install is always recommended).

However, depending on functionality in a JAR that doesn't hold OSGi headers is not an unlikely predicament to find yourself in.

The steps to work around such situation are not complicated. Here, you'll see one way of doing it— the manual way, which works well for very simple JARs like this one. In Chapter 14, Pitfalls and Troubleshooting, you'll be introduced to another way of achieving a similar result, using the BND tool. This tool goes deeper into the analysis of the JAR to be augmented with OSGi headers.

The following are the steps to follow:

  1. Download the dependency and save it somewhere on your disk. It can be found in the Maven repository used previously: http://repo2.maven.org/maven2/org/json/json/20090211/json-20090211.jar. I've saved the JAR in the following directory: P:/projects/felixbook/repackaged/.
  2. Unzip it and edit the META-INF/MANIFEST.MF. Not a lot of headers are needed for a simple library dependency— the exported packages and a few additional headers for a clean display and proper version registration (for potential updates later).

    The Manifest should look like the following:

    Manifest-Version: 1.0
    Created-By: 1.6.0_07 (Sun Microsystems Inc.)
    Export-Package: org.json
    Bundle-Name: JSON
    Bundle-Version: 20090211
    Bundle-SymbolicName: org.json
    
  3. Re-bundle the JAR with the updated manifest, using a ZIP archiver. Ensure that the files in the archive are under the correct root. This is a common JAR manipulation human error. In this case, the classes must be under org/json. To keep the original JAR separate from the repackaged JAR, I've repackaged the updated one as json-20090211-osgi.jar.
  4. Install and start it on the framework:
g! repack = file:///P:/projects/felixbook/repackaged/

g! start $repack/json-20090211-osgi.jar
  • The dependencies should now be satisfied and the result should be:
g! lb
START LEVEL 5
ID|State |Level|Name
0|Active | 0|System Bundle (3.0.1)
1|Active | 1|Apache Felix Bundle Repository (1.6.2)
2|Active | 1|Apache Felix Gogo Command (0.6.0)
3|Active | 1|Apache Felix Gogo Runtime (0.6.0)
4|Active | 1|Apache Felix Gogo Shell (0.6.0)
5|Active | 2|Bookshelf Inventory API (1.5.0)
6|Active | 1|Apache Felix iPOJO (1.6.4)
7|Active | 2|Bookshelf Inventory Impl - Mock (1.9.0)
8|Active | 1|Bookshelf Log Helper API (1.10.0)
9|Active | 1|Apache Felix Log Service (1.0.0)
10|Active | 1|Bookshelf Log Helper Impl (1.10.0)
11|Active | 3|Bookshelf Service (1.10.0)
12|Active | 5|Apache Felix iPOJO Gogo Command (1.0.0)
13|Active | 5|Bookshelf Service Gogo commands (1.10.0)
14|Active | 4|Apache Felix Http Jetty (2.0.4)
15|Active | 4|Apache Felix Http Whiteboard (2.0.4)
16|Active | 5|Bookshelf Servlet (1.11.0)
17|Active | 1|Apache Commons IO Bundle (1.4.0)
18|Active | 1|Apache Commons FileUpload Bundle (1.2.1)

19|Active | 1|JSON (20090211.0.0)

Let's install and start the web management console.

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

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