Java Reference
In-Depth Information
The final file needed in your WAB is the bundle manifest. Every JAR has a MANI-
FEST.MF file, but an OSG i bundle's manifest has extra headers, such as the symbolic
name of the bundle and the bundle's version.
Listing 2.3
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: fancyfoods.web
Bundle-Version: 1.0.0
Bundle-ClassPath: WEB-INF/classes
Web-ContextPath: /fancyfoods.web
Import-Package: javax.servlet.http;version="[2.5,3.0)",
To be consistent with the layout of a WAR , the class files for fancyfoods.web have been
packaged in the WEB-INF /classes folder. But there's no need for this. Classes can live any-
where in an OSG i bundle, or even be spread across multiple locations. If the class files
aren't directly in the root directory, the classpath needs to be specified in the manifest:
Bundle-ClassPath: WEB-INF/classes
Packages used by the servlet that aren't in the servlet's own bundle must be explicitly
imported in the manifest. Otherwise, they won't be visible. The exception is that
there's no need to import the core Java language classes, java.* , which are implicitly
imported. Bundle wiring rules are a bit different for the java.* packages, which must
come from the core Java runtime for security and for compatibility with the virtual
machine. Imagine if someone could replace the implementation of String or Integer!
In the case of the web bundle, this means the javax.servlet and javax.serv-
let.http packages are imported. The servlet is expected to work with any version of
javax.servlet with version 2.5 or higher, up to but not including version 3.0.
Import-Package: javax.servlet.http;version="[2.5,3.0)",
WARNING: WHAT ABOUT SERVLET 3.0? The meaning of the version range
"[2.5, 3.0)" isn't entirely straightforward. You're mostly right if you assume
that the 2.5 part implies version 2.5 of the servlet specification. But 3.0 defi-
nitely doesn't mean version 3.0 of the servlet specification! Remember, OSGi
versions are semantic package versions, not marketing or specification ver-
sions. Servlet 3.0 is backwards compatible with servlet 2.5, and so the package
versions for servlet 3.0 won't be versioned at 3.0. Version 3.0 of the servlet
packages would be some change to the servlet specification so radical that the
interfaces were no longer backwards compatible. The reason the bottom
range starts at 2.5 and not 1.0 is that when the WAB specification was written,
the current version was 2.5, and so 2.5 seemed like a logical starting point.
Unfortunately, some application servers have deviated from the semantic ver-
sion and use the package version 3.0 for the servlet 3.0 specification, which
doesn't help!
Search WWH ::

Custom Search