[英]JSP in OSGi: How to load TLD from bundles?
我們正在構建一個JSP Web應用程序,它在Apache Felix OSGi容器內運行(Web應用程序本身是一個OSGi Bundle)。 現在,我們面臨以下問題:
根據JSP 2.0規范,TLD(taglib描述符)不再需要駐留在Web應用程序WEB-INF文件夾中,而是直接從taglib的jar META-INF文件夾加載。 這個taglib jar通常駐留在web應用程序WEB-INF / lib文件夾中,但因為它們是OSGi包,所以它們由Felix加載。
在taglib的OSGi信息中,我們確實導入了所有需要的包。 那里的任何人都知道如何告訴servlet,在加載的OSGi Bundles中搜索TLD?
謝謝你的幫助!
如果他們與您的網絡應用程序不同, Pax將找不到您的TLD :
標簽庫
為了使您的自定義標記庫工作,您的TLD文件必須在“特殊”位置的捆綁中可訪問:
- Bundle-ClassPath清單條目引用的任何jar中的所有tld文件
- WEB-INF目錄中的所有tld文件或bundle jar中WEB-INF的子目錄
請注意,不會搜索您導入的軟件包(稍后可能會添加此支持)
我在基於Struts的系統中遇到了這個問題,我在多個webapp包之間共享一個OSGi-fied Struts包。 Web應用程序具有需要Struts標記庫的JSP。
稍微有點hackish(因為它復制了TLD的所有地方)解決方法是將TLD放在webapp的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>
通常,很難集成OSGi和Java EE庫。 來自Nuxeo CMS的人們設法集成了Seam Framework和OSGi,因此我認為使用他們的想法,您可以更輕松地集成JSP TLD和OSGi。 只需下載Nuxeo並分析其源代碼: http : //www.nuxeo.org/xwiki/bin/view/Main/
但是,集成OSGi和Java EE通常很難。 您真的需要OSGi運行時集成嗎? 也許Maven編譯時集成對你來說已經足夠了? 很多人只看到Maven和類似工具的編譯時OSGi。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.