OSGi 中的 JSP:如何从捆绑包加载 TLD?

发布于 2024-09-10 19:18:26 字数 371 浏览 4 评论 0原文

我们正在构建一个 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 捆绑包中搜索 TLD 吗?

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

留蓝 2024-09-17 19:18:26

如果您的 TLD 与您的网络应用程序位于不同的捆绑包中,Pax 将找不到您的 TLD :

标签库

为了让您的自定义标记库正常工作,您的 TLD 文件必须可以在捆绑包中的“特殊”位置访问:

  • Bundle-ClassPath 清单条目引用的任何 jar 中的所有 tld 文件
  • 捆绑 jar 中 WEB-INF 目录或 WEB-INF 子目录中的所有 tld 文件

请注意,您导入的包不会被搜索(可能稍后会添加此支持)

我在基于 Struts 的系统,我在多个 Web 应用程序包之间共享 OSGi-fied Struts 包。 Web 应用程序具有需要 Struts 标记库的 JSP。

一个稍微有点 hackish(因为它会复制 TLD 到各处)的解决方法是将 TLD 放入 web 应用程序的 META-INF 目录中,并使 web 应用程序包导入所需的 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>

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>
骄兵必败 2024-09-17 19:18:26

一般来说,集成 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。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文