JSP in OSGi: How to load TLD from bundles?
We're building a JSP web application, which runs inside the Apache Felix OSGi container (the web app itself is a OSGi Bundle). Now, we're facing the following problem:
According to the JSP 2.0 Spec, TLD (taglib descriptors) no longer need to reside inside the web apps WEB-INF folder, but are loaded directly from the taglib's jar META-INF folder. This taglib jars usually reside inside the web apps WEB-INF/lib folder, but because they're OSGi bundles, they're loaded by Felix.
In the taglib's OSGi info, we do import all the needed packages. Anyone out there how knows how to tell the servlet, to search for TLDs also inside the loaded OSGi Bundles?
Thanks for your help!
Pax won't find your TLDs, if they are in a bundle different from your webapp:
Tag Libs
In order to get your custom tag libs working your TLD files will have to be reachable in your bundle in "special" places:
Please note that your imported packages will not be searched (it may be that this support will be added later on)
I'm having this problem in a Struts-based system where I share an OSGi-fied Struts bundle between multiple webapp bundles. The webapps have JSPs that need the Struts taglib.
A slightly hackish (because it copies the TLD all over the place) workaround is putting the TLD in your webapp's META-INF
directory and make the webapp bundle import required Struts packages (or, if you don't use Struts, whatever classes process the tags). This can be automated with Maven like so:
<plugin>
<!--
Extract the TLD file from the Struts bundle you are using
and place it in src/main/resources/META-INF of your webapp's
project directory during generate-resources. This will make
the file end up in the appropriate place in the resulting WAR
-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>extract-tld</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts.version}</version>
<outputDirectory>src/main/resources</outputDirectory>
<includes>META-INF/struts-tags.tld</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!--
Add the required Manifest headers using the maven-bundle-plugin
-->
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<!-- ... -->
<instructions>
<!-- ... -->
<Import-Package>[...],org.apache.struts2.views.jsp</Import-Package>
<!-- ... -->
</instructions>
</configuration>
</plugin>
In general, it's hard to integrate OSGi and Java EE libraries. People from Nuxeo CMS managed to integrate Seam Framework and OSGi, so I think that using their ideas, you can integrate JSP TLD and OSGi as well, even more easily. Just download Nuxeo and analyze its source code: http://www.nuxeo.org/xwiki/bin/view/Main/
However integrating OSGi and Java EE is in general hard. Do you really need OSGi runtime integration. Perhaps Maven compile-time integration will be enough for you? Many people just see Maven and similar tools as compile-time OSGi.
链接地址: http://www.djcxy.com/p/2080.html上一篇: 是否有算法来排序GPU的字符串数组?