marczeeee
marczeeee

Reputation: 181

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. All the UI parts (xhtml files, js, css etc.) loaded from jar files within the war's WEB-INF/lib directory. All the resource files are put under META-INF/resource directory in the jars.

But I have issues with resource loading: the xhtml files loaded from the jars, but nothing else. When I try to load a js or css file directly it gives me a 404 error. Xhtml files can be loaded directly with their urls. 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.

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. 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. 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

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. 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. 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.

Upvotes: 1

Views: 585

Answers (1)

marczeeee
marczeeee

Reputation: 181

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 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. So simply uses it's own WebappClassloader instance. This is why all the resources of the application don't get loaded.

Upvotes: 1

Related Questions