Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2.0 app does not find resource

I am new to developing on JSF (and new to web development in general) and I am trying to put an image on a page. I'm developing my JSF app in Eclipse and running it on Glassfish 3.1.2. I have registered Glassfish as a server in Eclipse, and running the app via Eclipse.

I use the following markup on my xhtml page:

<h:graphicImage library="images" name="logo.png"/>

I copied the image in META-INF/resources/images/logo.png . The image does not appear on the page and when I view the page source I see the element

<img src="RES_NOT_FOUND" />

indicating that the image is not found.

When I export my app to a war file and deploy it onto Glassfish via the autodeploy folder, I get the same results - the page displays, but the image does not appear.

Can anyone advise why the image resource is not found?

like image 554
bgh Avatar asked Mar 08 '26 22:03

bgh


1 Answers

I copied the image in META-INF/resources/images/logo.png

This location will only work if the project represents a standalone module JAR which ultimately ends up in /WEB-INF/lib of the WAR.

This does not seem to the case in your particular case. Nothing in your question indicates that you're indeed developing a module JAR file. Apparently you've placed it straight in the WAR this way. This is not right.

You need to put the /resources folder straight in the public web content, not in the META-INF folder.

WebContent
 |-- META-INF
 |-- WEB-INF
 |    |-- faces-config.xml
 |    `-- web.xml
 |-- resources
 |    `-- images
 |         `-- logo.png
 `-- index.xhtml

See also:

  • Structure for multiple JSF projects with shared code
  • Why some resource files are put under META-INF directory

Unrelated to the concrete problem, using images as library name does not look entirely right. Just use

<h:graphicImage name="images/logo.png"/>

See also:

  • What is the JSF resource library for and how should it be used?
like image 194
BalusC Avatar answered Mar 10 '26 15:03

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!