As of release 6.1.5, Jetty ships with jar file manifests that include appropriate OSGi bundle information. This means that you can import the jetty jars into an OSGi framework and use them, for example, to build a HTTP service.
The jetty jars whose manifests include OSGi bundle information are:
Using jetty jars in Equinox
The jetty bundles mostly have dependencies amongst themselves (loosely in the order listed above), although the
jetty-naming.jar and the the jsp jars do have external dependencies.
If you are using Equinox, it is quite easy to resolve these dependencies. Here's a pre-baked Equinox config.ini file with all the external dependencies already setup up so that they will be loaded at start up time. Assuming you downloaded the config.ini file to
/tmp, here's a quick way to start up Equinox 3.3 with this config.ini file:
If you want to store the config.ini file somewhere else, then you need to include it's location on the command line:
There are more instructions for alternative ways to start Equinox on the Eclipse Equinox website.
Now you should be running Equinox, and you should see a prompt like so:
To see the state of all the bundles which are currently enabled, do:
You'll see output something like the following:
You can now go ahead and import the jetty jars. This is a matter of using the
install command to load each of them. Assuming I have jetty 6.1.5 installed in
/home/janb/src/jetty-6.1.5, I install the servlet-api-2.5 jar and check on it's status by doing:
The final step is to
start that jar so that it is available to the OSGi environment:
Rinse and repeat for all the jars we listed at the top of this article and you will have successfully imported and made available the jetty jars in OSGi!
OSGi dependency resolution, and a closer look at the Equinox config.ini file
As we said before, jetty is mostly self-contained. There are a few jars (aka bundles in OSGi-speak) which do, however, have external dependencies and these must be resolved before you will be able to fully use jetty. If you are using the supplied config.ini file, then this is already solved for you. However, if you are using a different OSGi framework, or you'd like to understand a bit more about dependency resolution, then read on.
The jars and their external package dependencies are:
All of these, except for
org.eclipse.jdt. can all be found in the jvm's
rt.jar. In Equinox, by default, these system packages from the system classloader are not exposed inside the OSGi framework. So, we need to expose them by using this setup in the config.ini:
To resolve the
org.eclipse.jdt. packages - which equate to the
ant.jar and the
core.jar from the jetty distribution - we need to use these Eclipse plugins (note, this page was created based on Eclipse 3.3, so the plugin versions may change depending on your Eclipse version):
These plugins have their own dependencies which need to be resolved, and so we end up with this list of bundle dependencies, which we instruct Eclipse to pre-load for us, rather than manually installing and resolving each one: