Pax won't find your TLDs,如果他們在您的Web應用程序不同的捆綁產品:
標記庫
爲了讓您的自定義標籤庫的工作您的TLD文件將必須在到達你捆綁在「特殊」地方:
- Bundle-ClassPath清單條目引用的任何jar中的所有tld文件
個
- 在WEB-INF目錄或WEB-INF的子目錄中的所有TLD文件在你的包JAR
請注意,你導入的包不會被搜索(這可能是因爲這種支持將在稍後加入)
我在基於Struts的系統中遇到了這個問題,在這個系統中,我在多個webapp包之間共享一個OSGi-fied Struts包。 Web應用程序具有需要Struts taglib的JSP。
一個稍微不成熟的問題(因爲它將TLD複製到所有地方)解決方法是將TLD放入您的Web應用程序的META-INF
目錄中,並使webapp bundle導入爲必需Struts包(或者,如果您不使用Struts,處理標籤)。這可以通過Maven自動執行,如下所示:
<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>
JSP容器是否在OSGI環境之外啓動,或者它是一個包? – 2010-07-23 13:38:13
這是一個包。我們使用OPS4J Pax Web(http://wiki.ops4j.org/display/paxweb/Pax+Web) – Basil 2010-07-27 19:52:21