I am currently using JSF on glassfish for generating emails inside of a EJB. I based my work on the following blog post:
Basically it works when the JSF is rendered in a request that was made from the web.
I currently try to also use JSF in unit tests and scheduled executions but I currently have trouble to start JSF.
The following class is doing the initialization of Faces:
com.sun.faces.config.FacesInitializer
Unfortunately it requires a complete implementation of the Servlet 3.0 implementation. In my cases starting the servlet engine also requires an JMX server.
From my current experience I would recommend to use a template engine with less dependencies e.g.
- Velocity http://velocity.apache.org/
- Freemarker http://freemarker.org/