jsf-2 -/WEB-INF/lib 外部共享库 JAR 中的常见 Facelets 文件

标签 jsf-2 jar shared-libraries facelets filenotfoundexception

我有一个公共(public)共享库(在 Websphere 应用程序服务器中设置为共享库)。

该jar的文件夹结构是:

UtilityJAR
----src
       -com
          -test
            -TestClass.java
---- META-INF
       -resources    
          -template.xhtml
          -css
             -style.css

在我的网络项目中,我有一个名为 User.xhtml 的模板客户端文件,它使用上述共享库中的模板文件
ui:composition  template="/template.xhtml"

当我在 Web 应用程序的 WEB-INF/lib 文件夹中有上述 jar 文件时,该应用程序工作正常,没有任何问题(模板.xhtml 被识别)。当我从该应用程序的 Lib 文件夹中删除 jar 并将其作为共享库放在 Websphere 中时(因为我需要来自 4 个以上应用程序的这个 jar 文件,并且我不想在所有 4 个应用程序中复制这个 jar),我收到以下错误消息。
[9/24/14 14:09:17:936 EDT] 00000113 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: java.io.FileNotFoundException: /template.xhtml Not Found in ExternalContext as a Resource

Utility jar 中包含 faces-config 和 @ManagedBean 注释,当 jar 位于应用程序的 WEB-INF/lib 文件夹中时,这些注释可以工作。

以前有人遇到过这个问题吗?谢谢你的帮助。

最佳答案

包含 webapp 资源的 Web 片段 JAR 必须 放在webapp的/WEB-INF/lib .

来自 Servlet 3.0 specification第 37 页(强调我的):

4.6 Resources

...

The getResource and getResourceAsStream methods take a String with a leading “/” as an argument that gives the path of the resource relative to the root of the context or relative to the META-INF/resources directory of a JAR file inside the web application’s WEB-INF/lib directory. These methods will first search the root of the web application context for the requested resource before looking at any of the JAR files in the WEB-INF/lib directory. The order in which the JAR files in the WEB-INF/lib directory are scanned is undefined. This hierarchy of documents may exist in the server’s file system, in a Web application archive file, on a remote server, or at some other location.

...



如果您真的想将它们放在其他地方(坏主意!),那么您需要自行开发一个自定义 Facelets 资源解析器。您可以在此处找到启动示例:How to create a modular JSF 2.0 application?

也可以看看:
  • JSF facelets template packaging
  • 关于jsf-2 -/WEB-INF/lib 外部共享库 JAR 中的常见 Facelets 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26023831/

    相关文章:

    c - 位置独立代码、共享库和代码贴面——让它们协同工作

    java - 使用 log4j 为每个 Web 应用程序和共享库分离日志文件

    java - 向 JSF 2 数据表动态添加行组件

    中继器的 JSF2 寻呼/寻呼机

    java - 在 SBT 中,可以自动命名私有(private)包吗?

    c++ - 链接boost库时程序无错退出

    java - 除非重新启动 Glassfish 服务器,否则不会反射(reflect)属性文件更改

    html - primefaces:如何在 <p:layoutUnit> 中禁用 css

    从 .jar 文件加载 Java 图像

    java - 如何制作WebDriver项目的Java可执行Jar文件