You can, of course, simply place the new javax.faces dependency within the pom.xml above your glassfish dependency to build your app. But this will not prevent someone from deploying to a non-customized glassfish install.
To prevent the application from running at all, you're going to have to do a library version check within a Filter and throw a ServletException if it doesn't match the expected version. This won't prevent a deployment, but this is the next most intrusive option since it all requests will respond with a ServletException.
For example:
import java.io.IOException;
import javax.faces.application.ResourceHandler;
import javax.faces.context.FacesContext;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
@WebFilter(value = "/*", dispatcherTypes = { DispatcherType.REQUEST, DispatcherType.FORWARD })
public class RelativePathFacesFilter implements Filter {
private static String EXPECTED_FACES_VERSION = "2.2.6";
private String facesVersion;
private boolean correctVersion;
@Override
public void init(FilterConfig filterConfig) throws ServletException {
facesVersion = FacesContext.getCurrentInstance().getClass().getPackage().getImplementationVersion();
correctVersion = EXPECTED_FACES_VERSION.equals(facesVersion);
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if (!correctVersion) {
throw new ServletException("Expected Faces version=" + EXPECTED_FACES_VERSION + ", but instead got " + facesVersion);
}
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
}