views:

80

answers:

2

Hi!

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!

+1  A: 

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:

  • all tld files in any jar referenced by your Bundle-ClassPath manifest entry
  • all tld files in WEB-INF directory or sub-directory of WEB-INF in your bundle jar

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>
Hanno Fietz
Hanno, thanks for your good explaining and helpful answer. I'll try your 'hack' in our environment. Anyway, I still hope "that this support will be added later on", as stated in the OPS4J doc.
Myniva
A: 

In general, it's hard to integrate OSGi and JEE 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 JEE 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.

iirekm