JSF 2.0 app does not find resource - eclipse

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?

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?

Related

What is the path for html file, to access it

I created Dynamic Web Project In Eclipse and created some html pages.
I have another Maven Project Of Java REST API. In Maven Project src->main->webapp->WEB-INF , I pasted my html, so i want to access this html pages, so what should be the path ?
Please Check Image,
Your UI resources should not be under WEB-INF folder. You should place your html and CSS folder directly under webapp. You can then access it by URL http://localhost:port/InteractDemo/html (port must be modified as per the server)

Deploy OpenUI5 on phoenixframework

I created my first openui5 hello world application on eclipse and want to deploy on my phoenix(elixir webserver) server.
Application structure:
And the app looks as follow:
My question is, how make the application ready to deploy?
Its all static content. Copy all files and folders inside Webcontent to your web server. You can put it to the web servers root, but you don't have to. WEB-INF and META-INF are not needed.
Then copy the openui5 framework to the Webserver to a folder of your choice. You may have to change the bootstrap element to point to your sap-ui-core.js.
That's it. Optionally You can use the grunt-openui5 plugin to build a packaged preload file of your application.

The generated war after the deploy, does not see the servlets

I generated two war files, one using export-> war file in Eclips second using maven-war-plugin. When I deploy this war in localhost tomcat7 or on an external server, the Tomcat application can not find the servlet. Links that point to servlets returns a 404 error
War is correctly deployowany because the home page is displayed correctly.
Eclipse does not show any errors in servlets so I say that's not the problem.
Deploy war directory structure looks like this:
css, fonts, img, js, loess, META-INF, pages, WEB-INF (with epmpty controller folder and the folder lib with my jar eg. Mysql_connector). But nowhere I can not see the folders with my model
Does anyone have any idea why this is happening?

Maven web project issue

I'm using Eclipse IDE for EE development(Kepler SR1).
Using Maven 3.1.0, I'm trying to create a simple web project. Accordingly, in Eclipse, I select maven-archetype-webapp and proceed.
But when the project is created, under 'Java resources', only src/main/resources is seen. When I check the build path, it shows src/main/java and src/test/java as missing.
Obviously, when I created a simple servlet under src/main/resources, I got a ClassNotFoundException for the servlet - I believe that the Servlet class didn't get compiled as my Maven basic folder structure itself is missing !
What could be the problem? I don't see any reason to make/create any source folder entries manually if I'm getting the option of 'maven-archetype-webapp' in the Eclipse IDE.
There's nothing in the documentation to suggest that the maven-archetype-webapp archetype will create a servlet class for you.
The documentation for this archetype shows this structure as the end result:
project
|-- pom.xml
`-- src
`-- main
`-- webapp
|-- WEB-INF
| `-- web.xml
`-- index.jsp
The archetype description does state that is a "An archetype which contains a sample Maven Webapp project.", and it certainly is.
You'll need to use another archetype, or create your own. An alternative approach is the Eclipse WTP integration to eclipse-ify your maven project. It's been a while since I tried, but iirc that worked pretty well.

eclipse dynamic web project file locations

I'm creating a new dynamic web project in Eclipse and was wondering what best practices are for folder taxonomy. Here's what I believe it is <> are folders. Can someone please verify?
<Eclipse project name>
<src>
-- .java files
<WebContent>
-- .html pages
<images>
<css>
<js>
<META-INF>
MANIFEST.MF
<WEB-INF>
web.xml
<app name>
-- .jsp pages
Here is a sample folder structure of a dynamic web project:
As you can see all static files are placed as sub-folders under the WebContent folder. By naming conventions .css files are places in the css sub-folder. JavaScript .js files are placed under the js sub-folder and any image files such as .jpeg or .png are placed in the images sub-folder. I also have an extra lib sub-folder where I placed an angularjs library to be used.
By default after creation of a dynamic web project your web.xml file looks like so:
`<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>`
meaning it will first call the listed default name files when you run your application. This is why most projects will name the files as index.html or index.jsp. NOTE: that my index.html file is directly below the WebContent folder and not in a sub-folder
Finally you can call/include your static files (.css .js and image files) from your 'index' file like so:
<link rel="stylesheet" href=css/bootstrap.min.css>
<link rel="stylesheet" href=css/bootstrap-theme.min.css>
<script type="text/javascript" src="lib/angular.min.js"></script>
<script src="js/contactsApp.js"></script>
Also your .java files will properly go in the Java Resources -> src -> {place java files here}
Put your pages under WEB-INF folder, in that way they cannot be accessed directly.
Also look at maven directory layout http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html.
To what Aleksandr M said,
WebContent folder:
The mandatory location of all web resources, including HTML, JSP, graphic files, and so on. If the files are not placed in this directory(or in a sub directory structure under this directory), the files will not be available when the application is executed on the server.
WEB-INF
Based on the Sun Microsystems Java Servlet 2.3 Specification, this directory contains the supporting Web resources for a Web application, including the web.xml file and the classes and lib directories.
Source: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fccwebprj.html
I am not sure why having an app-name directory under WebContent would be considered a "best practice".
Other than that, one primary rule you should be following when coming up with a directory structure is to have all static resources under one directory. In your example, I would have a subdirectory called static under WebContent, and place the js, css and images directories under it.
That way, it'd be easier for you to (later on) configure your HTTP server to pick static resources directly from the file system rather than route requests for static resources through the servlet container.
I had this question too and can't comment yet, but Upendra Bittu's answer helped me.
http://help.eclipse.org/neon/index.jsp
Search 'jsp', click on "Creating JavaServer Pages (JSP) files"
Create a dynamic Web project if you have not already done so.
In the Project Explorer, expand your project and right click on your WebContent folder or on a subfolder under WebContent. Note that
if you choose any other folder in which to create the JSP, then it
will not be included in the WAR file that is deployed to the server.
In addition, link validation will not encompass files that are not
under the WebContent folder.
From the context menu, select New > JSP. The New Java Server Page window appears with your folder selected
I'm trying out tutorials and get lost when people don't say where they create their files, and this helped me understand what's going on, so I'm just passing it on.