共享库中的Common Facelets文件JAR在/ WEB-INF / lib之外 [英] Common Facelets files in shared library JAR outside /WEB-INF/lib
问题描述
我有一个通用的共享库(在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文件时,应用程序工作正常,没有任何问题(可识别template.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服务SRVE0014E:未捕获的service()异常根本原因Faces Servlet:java.io.FileNotFoundException:/template.xhtml在ExternalContext中找不到资源
Utility jar中有faces-config,并且当jar在应用程序的WEB-INF / lib文件夹中时,它具有@ManagedBean注释。 / p>
之前有人遇到过这个问题吗?谢谢你的帮助。
包含webapp资源的网页片段JAR 必须放在webapp的 / WEB-INF / lib
。
来自 Servlet 3.0规范第37页(强调我的):
< blockquote>
4.6资源
...
getResource
和 getResourceAsStream
方法采用带有前导
的字符串/
作为参数,提供相对于
上下文的根的资源路径或相对于
Web应用程序的WEB-INF中的 JAR文件的META-INF / resources目录的相对路径/ lib目录。在查看WEB-INF / lib目录中的任何
JAR文件之前,这些方法将首先在Web应用程序上下文的根
中搜索所请求的资源。扫描
WEB-INF / lib目录中的JAR文件的顺序是未定义的。这种文档层次结构可能是
存在于服务器的文件系统,Web应用程序存档文件,远程服务器,
或其他某个位置。
...
如果你真的想把它们放在别处(坏主意!),然后你需要自己生成一个自定义Facelets资源解析器。您可以在此处找到启动示例:如何创建模块化JSF 2.0应用程序?
另请参阅:
I have a common shared Library (that is setup as a Shared Library in Websphere Application server).
The folder structure of that jar is:
UtilityJAR
----src
-com
-test
-TestClass.java
---- META-INF
-resources
-template.xhtml
-css
-style.css
In my web Project, I have a template client file called User.xhtml that uses the template file from the above Shared Library using
ui:composition template="/template.xhtml"
When I have the above jar file in the WEB-INF/lib folder of the Web application, the application works fine without any issues (template.xhtml is recognized). When I remove the jar from the Lib folder of this application and put it as a Shared Library in Websphere (because I need this jar file from more than 4 applications and I don't want to copy this jar in all the 4 applications), I get the following error message.
[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
The Utility jar has faces-config in it and has @ManagedBean annotations that work when the jar is inside the application's WEB-INF/lib folder.
Anybody faced this problem before? thanks for your help.
Web fragment JARs containing webapp resources MUST be placed in webapp's /WEB-INF/lib
.
From Servlet 3.0 specification page 37 (emphasis mine):
4.6 Resources
...
The
getResource
andgetResourceAsStream
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....
If you really want to place them elsewhere (bad idea!), then you'd need to homegrow a custom Facelets resource resolver. You can find a kickoff example here: How to create a modular JSF 2.0 application?
See also:
这篇关于共享库中的Common Facelets文件JAR在/ WEB-INF / lib之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!