JSP in OSGi: How to load TLDs from packages?

We are creating a JSP web application that runs inside the OSGi Apache Felix container (the web application itself is the OSGi package). Now we are faced with the following problem:

According to the JSP 2.0 specification, TLDs (taglib descriptors) no longer need to be placed inside the WEB-INF folder of web applications, but are loaded directly from the META-INF taglib jar folder. These taglib banners are usually located inside the WEB-INF / lib folder of web applications, but since they are OSGi packages, they are downloaded by Felix.

In taglib OSGi info we import all the necessary packages. Anyone who knows how to tell a servlet to look for TLDs also inside downloaded OSGi packages?

Thank you for your help!

+7
java jsp osgi taglib
source share
2 answers

Pax will not find your TLDs if they are bundled different from your webapp:

Tag libs

For your custom tag libraries to work, your TLD files must be available in your package in β€œspecial” places:

  • all tld files in any bank referenced by your Bundle-ClassPath manifest entry
  • all tld files in the WEB-INF directory or the WEB-INF subdirectory in your package

Please note that your imported packages will not be found (perhaps this support will be added later)

I had this problem on a Struts-based system where I use the OSGi-fied Struts package between multiple Webapp packages. Webapps has JSPs that need the ull Struts tag.

A bit hacked (because it copies TLDs all over the place) a workaround is to place the TLDs in your webapp META-INF and create a Webapp package to import the necessary Struts packages (or, if you don't use Struts, so that classes handle tags). This can be automated using Maven as follows:

  <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> 
+3
source share

In general, it is difficult to integrate the OSGi and Java EE libraries. The people of Nuxeo CMS managed to integrate the Seam Framework and OSGi, so I think that using your ideas you can also integrate JSP TLD and OSGi is even easier. Just download Nuxeo and analyze its source code: http://www.nuxeo.org/xwiki/bin/view/Main/

However, the integration of OSGi and Java EE is generally complex. You really need OSGi runtime integration. Perhaps the integration during Maven compilation will be enough for you? Many people just see Maven and similar tools, such as compile-time OSGi.

0
source share

All Articles