Java Reference
In-Depth Information
Luckily, the Java compiler doesn't do this. If your declared dependencies aren't
present, the compilation will fail quickly. At runtime, on the other hand, you're in a
situation which is similar to the undeclared dependencies. You have to wait until your
class is invoked to discover its dependencies are missing. You won't ever end up run-
ning against a class from a totally different package to the one you expected, but you
could end up running with a class of a different version, with totally different methods
and behaviors.
Explicitly declaring the dependency on the javax.servlet and javax.servlet
.http packages ensures the fancyfoods.web bundle won't run in a container that
doesn't support servlets. Better yet, it won't even run in a container that supports an
obsolete version of the servlet specification. To try this out, go to the OSG i console for
the Aries runtime. At the prompt, use the packages command to see which bundles
import and export the javax.servlet package:
osgi> packages javax.servlet
The response should be something like that shown in figure 2.7.
The output shows that the org.apache.geronimo.specs.geronimo-servlet_2.5_spec
bundle exports the javax.servlet package, and five bundles import it, including
fancyfoods.web .
Does it matter who provides the servlet package?
Depending on which version of the Aries sample assembly you're using, your con-
sole output may be different from what's shown in figure 2.7. In particular, it may
be a different bundle that provides the javax.servlet package. Declaring depen-
dencies on packages, rather than bundles, allows more deployment flexibility. In
this case, the Aries team has taken advantage of that flexibility by swapping the
web container implementation.
What would happen if the Aries assembly hadn't included the Geronimo servlet API JAR ?
Quit the OSG i console, and move the Geronimo servlet bundle (geronimo-servlet*jar)
out of the target directory. (Don't lose it though!) Restart the OSG i console, and type
Figure 2.7 The OSGi console can provide the list of bundles providing and consuming the
javax.servlet package.
Search WWH ::

Custom Search