4

I have a common shared Library (that is setup as a Shared Library in Websphere Application server).

The folder structure of that jar is:

UtilityJAR
----src
       -com
          -test
            -TestClass.java
---- META-INF
       -resources    
          -template.xhtml
          -css
             -style.css

In my web Project, I have a template client file called User.xhtml that uses the template file from the above Shared Library using

ui:composition  template="/template.xhtml"

When I have the above jar file in the WEB-INF/lib folder of the Web application, the application works fine without any issues (template.xhtml is recognized). When I remove the jar from the Lib folder of this application and put it as a Shared Library in Websphere (because I need this jar file from more than 4 applications and I don't want to copy this jar in all the 4 applications), I get the following error message.

[9/24/14 14:09:17:936 EDT] 00000113 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0014E: Uncaught service() exception root cause Faces Servlet: java.io.FileNotFoundException: /template.xhtml Not Found in ExternalContext as a Resource

The Utility jar has faces-config in it and has @ManagedBean annotations that work when the jar is inside the application's WEB-INF/lib folder.

Anybody faced this problem before? thanks for your help.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user972391
  • 321
  • 1
  • 4
  • 20

1 Answers1

5

Web fragment JARs containing webapp resources MUST be placed in webapp's /WEB-INF/lib.

From Servlet 3.0 specification page 37 (emphasis mine):

4.6 Resources

...

The getResource and getResourceAsStream methods take a String with a leading “/” as an argument that gives the path of the resource relative to the root of the context or relative to the META-INF/resources directory of a JAR file inside the web application’s WEB-INF/lib directory. These methods will first search the root of the web application context for the requested resource before looking at any of the JAR files in the WEB-INF/lib directory. The order in which the JAR files in the WEB-INF/lib directory are scanned is undefined. This hierarchy of documents may exist in the server’s file system, in a Web application archive file, on a remote server, or at some other location.

...

If you really want to place them elsewhere (bad idea!), then you'd need to homegrow a custom Facelets resource resolver. You can find a kickoff example here: How to create a modular JSF 2.0 application?

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks @BalusC for your response. So, if I need to place the common template files in a jar, then I would have to include that in all my applications' LIB folder? (other than the custom resource resolver, any other way to do this?) – user972391 Sep 24 '14 at 18:41
  • That's correct. Should be effortless if you use a dependency management and build system like Maven. – BalusC Sep 24 '14 at 18:42
  • even with Maven, if I change the template file/java files in the jar, I have to build all the EAR files again for all the 5 applications with the updated jar? Isn't that why Shared Library is useful, just to replace the jar on the Websphere Shared Libraries and all the apps use this new jar after restart? – user972391 Sep 24 '14 at 18:44
  • Isn't that why Shared Library is useful, just to replace the jar on the Websphere Shared Libraries and all the apps use this new jar after restart? Is there a way to avoid creating 5 EAR files again and updating all the apps – user972391 Sep 24 '14 at 18:48
  • WebSphere's "Shared Library" thing is for Java SE based JARs (Apache Commons, Guava, etc) not for Java EE based Web Fragment JARs. The way of "avoiding" this is using a continuous integration system which does that all automatically (e.g. Jenkins, Hudson, etc). – BalusC Sep 24 '14 at 18:50
  • another follow up question. What happens to the @ ManagedBean classes etc that are in the Shared Library folder? Will they be scanned by JSF (with a faces-config file). I believe the Resource Resolver is only to resolve the facelet files. How do I get the java classes in the Shared Library scanned/used? – user972391 Sep 24 '14 at 19:11