Common Facelets files in shared library JAR outside /WEB-INF/lib - jsf-2

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.

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:
JSF facelets template packaging

Related

Web fragments (Servlet API 3.0) - Also modular resources in WEB-INF directory

According to Servlet 3.0, a JAR placed in WEB-INF/lib has static content from its META-INF/resource directory accessible from the web-context root.
The specification doesn't say anything about modular resources, which should be accessible from the WEB-INF directory.
I would like to create a modular project, where every module "adds" all files from its WEB-INF directory to the web-context/WEB-INF directory. Is it possible?
OK I understand.. Simply create a folder META-INF/resources/WEB-INF :)

Deploying JSF application on tomcat getting exception

When I'm deploying JSF2.0 application on tomcat6.0 I'm getting following exception:
com.sun.faces.lifecycle.ELResolverInitPhaseListener populateFacesELResolverForJsp
INFO: JSF1027: [null] The ELResolvers for JSF were not registered with the JSP c
ontainer.
I have included el-api2.2 and el-impl2.2 jar files in $TOMCAT_HOME/lib directory,as well as i have also included el-impl2.2.jar in my Project lib's folder.
I have included el-api2.2 and el-impl2.2 jar files in $TOMCAT_HOME/lib directory
Remove them. They don't belong there.
i have also included el-impl2.2.jar in my Project lib's folder.
If I guess right the concrete functional requirement which you didn't tell anything about, then you actually just want to get EL 2.2 to work on Tomcat 6.0. In that case, you should drop the mentioned JAR files in /WEB-INF/lib folder of your webapp and add the following entry to webapp's web.xml, assuming that you're indeed using Mojarra JSF implementation as hinted by the exception.
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>

how to compile java files classnotfoundexception

I am having a java project having the directory structure as
java->applet and a few .java files
the applet folder further contains two folders and some .java files
I need to develop a jar file out of this project
I did so by writing the command line
jar cvfm myfile.jar *.java
(obviously by moving into corresponding directory)
when I checked by extracting the file(it was zipped as a Nokia application installer file)
it showed me only the classes in the applet folder not the folders in it
moreover i needed to use this jar file in a jquery plugin where i had written
var dasherApplet = $('applet');
dasherApplet.attr({
'height':'100%',
'width':'100%',
'archive':farfalla_path+'plugins/dasher/jardasher.jar',
'code':'JDasherApplet.java'
});
but it showed me the class not found exception
for this I checked the previous versions of the java applet; there the java files were replaced by .class files so i tried compiling a java file into .class by using the command line
C:/>javac filename.java
still all in vain this time it showed me
"cannot find symbol" error
what was interesting was that the errors generated were imitating the java files present in the same folder. I navigated to the directory where the file was stored still the same error
when i tried to simply run it by using
java filename.java
error was main class not found:JApplet.java
Please help me develop this applet
Firstly you need to compile all the jar files before running.
Secondly , you CANNOT run Applets using java filename.java .
As this link explains http://download.oracle.com/javase/tutorial/deployment/jar/build.html ,
jar cvf TicTacToe.jar TicTacToe.class audio images
Here audio and images are folders , so that is how you add folders to jar.
Also .jar files are not Nokia Application Installer files . Nokia simply associates them for installing apps (that is J2ME)

External properties file with JSF2

I'd like to NOT put my properties file in the war file's classes directory. Can I do this and what would I specify in faces-config.xml for it to use the correct resource-bundle ?
Thanks
Binh Nguyen
Put it in an external folder and add its path to the runtime classpath. Then you can access it from the classpath the usual way as if it's in /WEB-INF/classes (which is just by default part of the classpath).
Adding the path to an external folder to the classpath is best to be configured at the webserver level. In Tomcat for example, you can specify it in the shared.loader or common.loader property of Tomcat's /conf/catalina.properties file.
shared.loader = /path/to/propertiesfiles

EJB calls from grails to glassfish

I need to use EJB remote calls from my grails application. For this in previouse Servlet application I used client glassfish jar(gf-client.jar) and is's worked.
How I can include gf-client.jar into build path in grails app for call EJB methodth?
thank you.
the answer was to copy all libraries of GlassFish application server to client mashine (directory with gf-client.jar and 2 levels up, check dependencies in gf-client.jar) and add only gf-client.jar to classpath of application. Ather dependencies will loaded automatically, when gf-client will loaded.
note 1: in my case for grails application witch I deploying to tomcat servlet container write full path to gf-client.jar to shared.loader section of catalina.properties file in conf dir, and restart tomcat.
note 2: for GlassFish v3.1 and up, replace gf-client.jar with gf-client-module.jar
Put gf-client.jar into the lib directory of your grails app. Any jar files in the lib directory of your grails app will automatically be included when you run your application as well as be packaged in generated war files.

Resources