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