简体   繁体   English

OSGi中的JSP:如何从bundle加载TLD?

[英]JSP in OSGi: How to load TLD from bundles?

We're building a JSP web application, which runs inside the Apache Felix OSGi container (the web app itself is a OSGi Bundle). 我们正在构建一个JSP Web应用程序,它在Apache Felix OSGi容器内运行(Web应用程序本身是一个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. 根据JSP 2.0规范,TLD(taglib描述符)不再需要驻留在Web应用程序WEB-INF文件夹中,而是直接从taglib的jar META-INF文件夹加载。 This taglib jars usually reside inside the web apps WEB-INF/lib folder, but because they're OSGi bundles, they're loaded by Felix. 这个taglib jar通常驻留在web应用程序WEB-INF / lib文件夹中,但因为它们是OSGi包,所以它们由Felix加载。

In the taglib's OSGi info, we do import all the needed packages. 在taglib的OSGi信息中,我们确实导入了所有需要的包。 Anyone out there how knows how to tell the servlet, to search for TLDs also inside the loaded OSGi Bundles? 那里的任何人都知道如何告诉servlet,在加载的OSGi Bundles中搜索TLD?

Thanks for your help! 谢谢你的帮助!

Pax won't find your TLDs , if they are in a bundle different from your webapp: 如果他们与您的网络应用程序不同, Pax将找不到您的TLD

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: 为了使您的自定义标记库工作,您的TLD文件必须在“特殊”位置的捆绑中可访问:

  • all tld files in any jar referenced by your Bundle-ClassPath manifest entry Bundle-ClassPath清单条目引用的任何jar中的所有tld文件
  • all tld files in WEB-INF directory or sub-directory of WEB-INF in your bundle jar WEB-INF目录中的所有tld文件或bundle jar中WEB-INF的子目录

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. 我在基于Struts的系统中遇到了这个问题,我在多个webapp包之间共享一个OSGi-fied Struts包。 The webapps have JSPs that need the Struts taglib. Web应用程序具有需要Struts标记库的JSP。

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). 稍微有点hackish(因为它复制了TLD的所有地方)解决方法是将TLD放在webapp的META-INF目录中并使webapp bundle导入所需的Struts包(或者,如果你不使用Struts,那么任何类都处理标签)。 This can be automated with Maven like so: 这可以通过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>

In general, it's hard to integrate OSGi and Java EE libraries. 通常,很难集成OSGi和Java EE库。 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. 来自Nuxeo CMS的人们设法集成了Seam Framework和OSGi,因此我认为使用他们的想法,您可以更轻松地集成JSP TLD和OSGi。 Just download Nuxeo and analyze its source code: http://www.nuxeo.org/xwiki/bin/view/Main/ 只需下载Nuxeo并分析其源代码: http//www.nuxeo.org/xwiki/bin/view/Main/

However integrating OSGi and Java EE is in general hard. 但是,集成OSGi和Java EE通常很难。 Do you really need OSGi runtime integration. 您真的需要OSGi运行时集成吗? Perhaps Maven compile-time integration will be enough for you? 也许Maven编译时集成对你来说已经足够了? Many people just see Maven and similar tools as compile-time OSGi. 很多人只看到Maven和类似工具的编译时OSGi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM