Yes, that's definitely possible, assuming that you're using JSF 2.0, part of Java EE 6.
As to the managed beans and other JSF classes like validators, converters, etc, just annotate them with @ManagedBean
, @FacesValidator
, @FacesConverter
, etc and package them in the JAR the usual way. You only need to provide a JSF 2.0 compatible /META-INF/faces-config.xml
file in the JAR.
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
</faces-config>
This way JSF will be triggered to scan the classes in the JAR for JSF specific annotations. Alternatively you can also just register them in the JAR's faces-config.xml
the JSF 1.x way.
As to Facelets resources, just drop them in /META-INF/resources
folder of the JAR. It'll be treated the same way as public webcontent of the WAR.
See also:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…