Introduction
This is an article where the content is discussing about how to solve an error message. The error message itself appear upon executing a Java web application. So, there is a Java web application using maven-based project structure. Furthermore, the Java web application is has a JSF library as part of it. In that case, it is better to check the configuration and setting for the Java web application. For a reference, just look at the first article. That first article has the title of ‘How to Create maven-based Web Application in NetBeans IDE’ which exist in this link. It is focusing on how to create a maven-based Java web application. Then, the second article is for adding JSF library to the Java web application. Just check the article with the title ‘How to Add JSF Library to a maven-based Web Application in NetBeans IDE’ of this link.
As an addition, the Java web application is using a Bootstrap layout which depends on several files. In other words, those files must be exist in the JSF files which is part of the Java application. It is necessary in order to apply the Bootstrap layout in the Java web applciation. Unfortunately, after defining those files in the JSF file, there is an error appear. It is a step which is very important for first troubleshooting step. Actually, the reason for performing the troubleshooting is because the Bootstrap layout does not working in the Java web application. Because of that, the next step is to check the source by executing the ‘View Source’ of the web browser. Then, the error exactly appear in the ‘View Source’ page. It does not render the correct path of the Bootstrap files. Instead, it is showing the ‘RES_NOT_FOUND’ value as in the image follows :
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE html public "-//W3C/DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title>Default Title</title> </h:head> <h:outputStylesheet name="css/bootstrap.min.css"> <h:body> <div class="container"> <h:outputScript name="js/bootstrap.min.js"> </div> </h:body> </html>
How to Solve the Error Message
So, in the introduction part above, the definition for the CSS file and also the Javascript file exist. But that kind of definition with that kind of format is triggering an error instead.
The following is the definition from the above script in order to define on the loading process of ‘CSS’ file :
<h:outputStylesheet name="css/bootstrap.min.css">
Following after, it is a definition in order to define on the loading process of ‘Javascript’ file :
<h:outputScript name="js/bootstrap.min.js">
Actually, the above definition is generating an error message which appear in the ‘View Source’ page as follows :
<?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt2"> <link type="text/css" rel="stylesheet" href="/demojava-1.0-SNAPSHOT/javax.faces.resource/theme.css.xhtml?ln=primefaces-admin&v=11.0.0" /> <link type="text/css" rel="stylesheet" href="/demojava-1.0-SNAPSHOT/javax.faces.resource/primeicons/primeicons.css.xhtml?ln=primefaces&v=11.0.0" /> <link type="text/css" rel="stylesheet" href="RES_NOT_FOUND" /> <script type="text/javascript">if(window.PrimeFaces){PrimeFaces.settings.locale='en_US';PrimeFaces.settings.viewId='/index-jsf-bootstrap.xhtml';PrimeFaces.settings.contextPath='/demojava-1.0-SNAPSHOT';PrimeFaces.settings.cookiesSecure=false;PrimeFaces.settings.projectStage='Development';}</script> <title>Default Title</title> </head> <body> <div class="container"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script type="text/javascript" src="RES_NOT_FOUND"></script> </div> </body> </html>
So, in order to solve, the following is the actual step to revise it :
-
Actually, the asset files which is generally a static file like CSS file, image file or even script file like Javascript file is in one exact folder. That is a folder with the name of ‘resources’. Furthermore, the location of the ‘resources’ folder in the Java web application’s folder structure is in th ‘Web Pages’ folder. In order to give a detail information, the following is the tree structure of the Java web application’s folder structure :
C:\cd demojava C:\demojava>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\demojava 05/17/2022 09:26 PM <DIR> . 05/03/2022 10:53 AM <DIR> .. 05/03/2022 05:04 PM 1,509 nb-configuration.xml 05/04/2022 01:28 PM 4,023 pom.xml 05/03/2022 10:53 AM <DIR> src 05/17/2022 09:26 PM <DIR> target 2 File(s) 5,532 bytes 4 Dir(s) 191,866,241,024 bytes free C:\demojava>cd src C:\demojava\src>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\demojava\src 05/03/2022 10:53 AM <DIR> . 05/17/2022 09:26 PM <DIR> .. 05/03/2022 10:53 AM <DIR> main 0 File(s) 0 bytes 3 Dir(s) 191,865,487,360 bytes free C:\demojava\src>cd main C:\demojava\src\main>cd resource The system cannot find the path specified. C:\demojava\src\main>dir Volume in drive C is Windows-SSD Volume Serial Number is CA30-19A4 Directory of C:\demojava\src\main 05/03/2022 10:53 AM <DIR> . 05/03/2022 10:53 AM <DIR> .. 05/03/2022 10:53 AM <DIR> java 05/15/2022 04:00 PM <DIR> resources 05/15/2022 08:36 PM <DIR> webapp 0 File(s) 0 bytes 5 Dir(s) 191,866,208,256 bytes free C:\demojava\src\main>tree . Folder PATH listing for volume Windows-SSD Volume serial number is CA30-19A4 C:\DEMOJAVA\SRC\MAIN ├───java │ └───com │ └───mycompany │ └───demojava │ └───resources ├───resources │ └───META-INF └───webapp ├───resources │ ├───css │ └───js ├───templates └───WEB-INF C:\demojava\src\main> cd webapp C:\demojava\src\main\webapps> cd resources C:\demojava\src\main\webapps\resources> tree . Folder PATH listing for volume Windows-SSD Volume serial number is CA30-19A4 C:\DEMOJAVA\SRC\MAIN\WEBAPP\RESOURCES ├───css └───js C:\demojava\src\main\webapps\resources>
-
As in the output command above, the location of the CSS and Javascript folder is actually in a folder with the name of ‘resources’. Specifically, it is a ‘resources’ folder in the ‘webapp’ folder. So, the path will be ‘demojava/src/main/webapp/resources.
-
Following after, it is not necessary to include the ‘css’ and ‘js’ folder for each of those file types as part of the source path. Instead, add an additional parameter with different value which is informing the folder name. Just look at the following definition for the revision for the CSS file :
<h:outputStylesheet library="css" name="css/bootstrap.min.css"/>
Furthermore, the following definition is the revision for the Javascript file :
<h:outputScript library="js" name="bootstrap.min.js"/>
-
After building, compiling and running it using NetBeans IDE in this context, the following is the actual appearance of the page :
-
Fortunately, the CSS and also the Javascript file available which is a success loading process as in the View Source page :