1

I am trying to store a set of JSF templates and other resources in a .jar file, which several webapps will draw from. I found this SO answer, which seems to provide instructions for the very thing I'm trying to do. However, while I can load images from the shared jar, I cannot get JSF templates to work. I get a file not found error.

I'm using Open Liberty 18.0.0.4, and the jar is stored in the ${server.config.dir}/lib/global directory, which I understand makes the contents available to all webapps.

Here is the output of jar tf of the shared jar.

META-INF/MANIFEST.MF
META-INF/resources/common/images/ufo.png
META-INF/resources/common/jsf/template.xhtml

This is the template.xhtml from the shared jar.

<?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://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Title from template</title>
    </h:head>
    <h:body>
        This is content from the template<br/>
    </h:body>
</html>

Turning to my webapp, here is the directory layout.

/WEB-INF
/WEB-INF/classes
/WEB-INF/web.xml
/META-INF
/imageTest.xhtml
/localTemplate.xhtml
/localJSFTest.xhtml
/sharedJarJSFTest.xhtml

The imageTest.xhtml simply displays the ufo.png from the shared jar, and this facelet works without a problem.

<?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://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Test Image</title>
    </h:head>
    <h:body>
        I can see this image.<br/>
        <h:graphicImage library="common" name="images/ufo.png" alt="ufo"/>
    </h:body>
</html>

The localJSFTest.xhtml uses the localTemplate.xhtml, which is part of the webapp. This also works.

localJSFText.html

<?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://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h:body>
        <ui:composition template="localTemplate.xhtml" />
    </h:body>
</html>

localTemplate.xhtml

<?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://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Title from local template</title>
    </h:head>
    <h:body>
        This is content from the LOCAL template<br/>
    </h:body>
</html>

The problem comes when sharedJarJSFText.xhtml tries to use template.xhtml (posted above) from the shared jar.

sharedJarJSFText.xhtml

<?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://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <h:body>
        <ui:composition template="/common/jsf/template.xhtml" />
    </h:body>
</html>

I get the following error when I try to access sharedJarJSFText.xhtml in the browser.

/common/jsf/template.xhtml Not Found in ExternalContext as a Resource

viewId=/sharedJarJSFTest.xhtml
location=/home/jmac/Programming/NetBeansProjects/TestJSFWebApp/src/main/webapp/sharedJarJSFTest.xhtml
phaseId=RENDER_RESPONSE(6)

Caused by:
java.io.FileNotFoundException - /common/jsf/template.xhtml Not Found in ExternalContext as a Resource
at org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:300)

I think I'm following the instructions in the above linked SO answer, so I'm not sure why this isn't working.

In another SO answer, user BalusC explains that since the Servlet 3.0 spec writing a custom ResourceResolver is unnecessary. This version of Open Liberty uses the Servlet 4.0 spec.

If helpful, here is the feature list from the server.xml for this Open Liberty server.

<featureManager>
    <feature>jsp-2.3</feature>
    <feature>jsf-2.3</feature>
</featureManager>

Thanks in advance for any suggestions.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Jared
  • 21
  • 3
  • Sorry, I misread your question – Kukeltje Mar 01 '19 at 18:58
  • No problem. I appreciate the quick reply. It is basically a duplicate question, but I can't get the duplicate question's answer to work. I had suspected that I was using Open Liberty wrong, so maybe I'm asking, how do I do this with Open Liberty? I thought maybe I was not activating a feature that I needed. But I just tried this on Payara 5, and I'm running into the same problem. I can get an image from the shared jar, but not the JSF template. Still, I imagine I'm overlooking something very basic. – Jared Mar 01 '19 at 19:36
  • Try adding the jar in your war. It might just be it does not work from a 'global' folder. And do you have an (empty) faces-config,xml in the jar? – Kukeltje Mar 01 '19 at 20:16

0 Answers0