简体   繁体   English

JSF资源加载问题(.xhtml加载,.css / .js / .gif等不加载)

[英]JSF resource loading issue (.xhtml loads, .css/.js/.gif etc doesn't)

I have a Liferay 6.0 instance running on Glassfish 3.0.1 with custom portlets written in JSF with RichFaces . 我有一个运行在Glassfish 3.0.1上的Liferay 6.0实例,该实例具有使用RichFacesJSF编写的自定义portlet。 All the UI parts (xhtml files, js, css etc.) loaded from jar files within the war's WEB-INF/lib directory. 从战争的WEB-INF/lib目录中的jar文件加载的所有UI部分(xhtml文件,js,css等)。 All the resource files are put under META-INF/resource directory in the jars. 所有资源文件都放在jars的META-INF/resource目录下。

But I have issues with resource loading: the xhtml files loaded from the jars, but nothing else. 但是我在资源加载方面遇到了问题:从jars加载了xhtml文件,但没有其他问题。 When I try to load a js or css file directly it gives me a 404 error. 当我尝试直接加载js或CSS文件时,出现了404错误。 Xhtml files can be loaded directly with their urls. Xhtml文件可以使用其URL直接加载。 I tried to play around with settings in web.xml, I added servlet-mappings for the Faces Servlet to handle *.js but it gave error 500 instead of 404. 我尝试使用web.xml中的设置,为Faces Servlet添加了Servlet映射以处理* .js,但它给出的错误为500,而不是404。

I'm pretty sure this is a resource loading configuration problem, but I have no idea how to fix it. 我很确定这是资源加载配置问题,但是我不知道如何解决。 If you have an idea, please help! 如果您有想法,请帮助! Thank you! 谢谢!

Update 更新

I managed to narrow the problem down a bit: the DefaultServlet of the Glassfish server receives the request and handles it to the WebappClassloader to find the requested resource. 我设法将问题缩小了一点:Glassfish服务器的DefaultServlet接收了请求,并将其处理到WebappClassloader以查找请求的资源。 For example if I try to load the /images/logo.gif file (stored in a jar within my war app) the classloader tries to find the file with META-INF/resources/images/logo.gif path. 例如,如果我尝试加载/images/logo.gif文件(存储在我的战争应用程序中的jar中),则类加载器将尝试使用META-INF/resources/images/logo.gif路径查找该文件。 The requested file actually is in that directory the classloader is looking for, so I don't understand why the classloader can't find this file. 所请求的文件实际上位于类装入器正在查找的目录中,因此我不明白为什么类装入器找不到此文件。

Update 2 更新2

With more debugging I was able to find the root of the problem: the classloader invoked to find the requested resource isn't the classloader of my application but the classloader of the Liferay portal. 通过更多的调试,我能够找到问题的根源:调用以查找所需资源的类加载器不是我的应用程序的类加载器,而是Liferay门户的类加载器。 If I open an URL like this: http://127.0.0.1/my-app/images/image1.gif the classloader serving behind the request won't be the one for my app but for the Liferay portal. 如果我打开这样的URL: http://127.0.0.1/my-app/images/image1.gif : http://127.0.0.1/my-app/images/image1.gif请求背后提供的类加载器将不是我的应用程序,而是Liferay门户网站。 In a VisualVM memory dump I could see my app also has a classloader instance with all it's jars loaded, but I don't know why Glassfish doesn't use that classloader. 在VisualVM内存转储中,我可以看到我的应用程序还具有一个classloader实例,其中包含所有jars,但我不知道为什么Glassfish不使用该classloader。

The problem was caused by the Liferay 6.0 version, as a newer versions of Liferay (6.1/6.2) work properly with the very same application and event with the very same Glassfish version. 此问题是由Liferay 6.0版本引起的,因为Liferay的较新版本(6.1 / 6.2)可以在具有相同的Glassfish版本的相同应用程序和事件中正常工作。 Liferay 6.0 catches all requests sent to the app server but cannot determine properly how should it handle the request and which WebappClassloader should be called for it. Liferay 6.0捕获所有发送到应用服务器的请求,但无法正确确定应如何处理该请求以及应为其调用哪个WebappClassloader So simply uses it's own WebappClassloader instance. 因此,只需使用它自己的WebappClassloader实例即可。 This is why all the resources of the application don't get loaded. 这就是为什么不加载应用程序的所有资源的原因。

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

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