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

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 :)

Related

Relative paths, MEF Directory Catalog and symlinks

Currently I have the same problem as: How do I get a MEF Directory catalog looking at the same directory for both the Servicelayer and DAL?.
I have a service say serviceWithMEF that initialises an MEF container. If this service is consumed by the web application project in the same solution, a relative path for the catalog such as ..\..\Extensions will search for the dll's two folders up from the web's root folder. However, if some other non-web project in the solution consumes it, it looks for the Extensions directory two folders up from \Debug\Bin instead.
I would like all projects in the same solution to look for the Extensions directory in the same place, without using absolute paths. serviceWithMEF currently gets the path ..\..\Extensions\ from the globalsettings.xml.
One possible solution I had was to create a symlink called 'Extensions' in all the projects folders and have the links point to the Extensions directory that the web application uses. However MEF doesn't seem to be treating the symlink as a directory.
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new DirectoryCatalog(Config.ExtensionPath));
leaves me with an empty catalog if I have a symlink that was created with mklink /D Extensions ..\..\Extensions, instead of an actual directory.
Any assistance would be appreciated

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

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

Grails copy resources to external dir

I would like to copy all the resources (js, css, bundles) created from grails (and its plugins cache, gzip, etc..) into an external folder (in S3) instead of inside the war.
Is it possible?
I've tried to check inside the documentation but with no result...
You can use grails.war.resources to customize war content. Take a look at section 18 of grails manual.

hibernate.cfg.xml path

I have a java project and I am using hibernate.The thing here is I want to place the hibernate.cfg.xml file outside "src" folder, but when I am configuring this file it is showing FileNotFoundException. If I put it inside src folder its ok. But I want to separate the java src and all config file in separate folder.
root
|____src
|____conf
|____mapping
|____(all xml file with hibernate.cfg.xml)
SessionFactory _sessionFactory = (new Configuration()).configure("./conf/mapping/hibernate.cfg.xml").buildSessionFactory();
Its showing exception......
Add conf/mapping directory to your CLASSPATH and load the configuration file
new Configuration().configure("/hibernate.cfg.xml").buildSessionFactory();
or just
new Configuration().buildSessionFactory();
as this is the standard name.
Regardless there would be no ./ at the beginning of the resource path.
What you want to do is
include conf/mapping in your project build path(With Eclipse properties->javabuild path->source->add Folder)
then no need to precise the hibernate config file in your code
new Configuration().buildSessionFactory(); is enough
This manipulation is simple and works like a charm.

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

Resources