I\'m trying to deploy a JSF based application to Tomcat 6. The way my build system is setup, the WAR itself doesn\'t have any libraries in it, because this server is serving
When you're facing a "weird" exception suggesting that classes/methods/files/components/tags are absent or different while they are seemingly explicitly included in the web application such as the ones below,
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet
java.util.MissingResourceException: Can't find javax.faces.LogStrings bundle
com.sun.faces.vendor.WebContainerInjectionProvider cannot be cast to com.sun.faces.spi.InjectionProvider
com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED
The tag named inputFile from namespace http://xmlns.jcp.org/jsf/html has a null handler-class defined.
java.lang.NullPointerException at javax.faces.CurrentThreadToServletContext.getFallbackFactory
java.lang.AbstractMethodError at javax.faces.application.ViewHandlerWrapper.getWebsocketURL
or when you're facing "weird" runtime behavior such as broken HTTP sessions (jsessionid
appears in link URLs over all place), and/or broken JSF view scope (it behaves as request scoped), and/or broken CSS/JS/image resources, then the chance is big that the webapp's runtime classpath is polluted with duplicate different versioned JAR files.
In your specific case with the ClassFormatError
on the FacesServlet
, it means that the JAR file containing the mentioned class has been found for the first time is actually a "blueprint" API JAR file, intented for implementation vendors (such as developers working for Mojarra and MyFaces). It contains class files with only class and method signatures, without any code bodies and resource files. That's exactly what "absent code attribute" means. It's purely intented for javadocs and compilation.
provided
All dependencies marked "Java Specifications" in Maven and having -api
suffix in the artifact ID are those blueprint APIs. You should absolutely not have them in the runtime classpath. You should always mark them
if you really need to have it in your pom. A well known example is the Java EE (Web) API:
javax
javaee-web-api
provided
If the provided
scope is absent, then this JAR will end up in webapp's /WEB-INF/lib
, causing all trouble you're facing now. This JAR also contains the blueprint class of FacesServlet
.
In your specific case, you have an unnecessary JSF API dependency:
javax.faces
javax.faces-api
This is causing trouble because this contains the blueprint class of FacesServlet
. Removing it and relying on a provided
Java EE (Web) API as shown above should solve it.
Tomcat as being a barebones JSP/Servlet container already provides JSP, Servlet and EL (and since 8 also WebSocket) out the box. So you should mark at least jsp-api
, servlet-api
, and el-api
as provided
. Tomcat only doesn't provide JSF (and JSTL) out the box. So you'd need to install it via the webapp.
Full fledged Java EE servers such as WildFly, TomEE, GlassFish, Payara, WebSphere, etc already provide the entire Java EE API out the box, including JSF. So you do absolutely not need to install JSF via the webapp. It would only result in conflicts if the server already provides a different implementation and/or version out the box. The only dependency you need is the javaee-web-api
exactly as shown here above.
The proper way to install JSF in Tomcat is mentioned in our JSF wiki - Installing JSF. There are 2 JSF implementations, Mojarra and MyFaces. You should choose to install one of them and thus not both.
Installing Mojarra on Tomcat:
org.glassfish
jakarta.faces
You can also check org.glassfish:jakarta.faces repository for current latest release version (which is currently 2.3.14
). See also Mojarra installation instructions
Installing MyFaces on Tomcat:
org.apache.myfaces.core
myfaces-bundle
You can also check org.apache.myfaces.core:myfaces-bundle repository for current latest release version (which is currently 2.3.5
).
Note that Tomcat 6 as being Servlet 2.5 container supports max JSF 2.1.
Don't forget to install JSTL API along, by the way. This is also absent in Tomcat.
jakarta.servlet.jsp.jstl
jakarta.servlet.jsp.jstl-api
Also note that since JSF 2.3, CDI has become a required dependency. This is available out the box in normal Java EE servers but not on servletcontainers such as Tomcat. In this case head to How to install and use CDI on Tomcat?