Apache MyFaces 无法在JBoss-5.0.1GA中直接使用
使用Eclipse WTP创建动态网页项目,添加JSF Facets之后,如果使用的是Apache MyFaces而且最后项目又是在JBoss-5.0.1GA中运行的话,一个简单的JSF页面就会导致“java.lang.RuntimeException - Cannot find FacesContext”的错误。检查了一下日志,发现项目在发布的时候就已经出错了,出错信息是:
ERROR [MyfacesConfig] Both MyFaces and the RI are on your classpath. Please make sure to use only one of the two JSF-implementations.
17:45:47,742 INFO [FacesConfigurator] Reading standard config META-INF/standard-faces-config.xml
17:45:48,021 INFO [FacesConfigurator] Reading config /WEB-INF/faces-config.xml
17:45:48,040 INFO [FacesConfigurator] MyFaces-package : myfaces-api not found.
17:45:48,040 INFO [FacesConfigurator] MyFaces-package : myfaces-impl not found.
17:45:48,040 INFO [FacesConfigurator] MyFaces-package : tomahawk-sandbox15 not found.
17:45:48,041 INFO [FacesConfigurator] MyFaces-package : tomahawk-sandbox not found.
17:45:48,041 INFO [FacesConfigurator] MyFaces-package : tomahawk not found.
将这个信息google了以后,找到MyfacesConfig类的源代码,发现该类在创建和初始化时会检测系统中是否分别存在org.apache.myfaces.application.ApplicationImpl和com.sun.faces.application.ApplicationImpl,前者则说明存在MyFaces JSF-Implementation,后者则说明存在SUN的RI JSF-Implementation。由于JBoss-5.0.1GA已经包含的SUN的JSF-Implementation,因此两个实现就冲突了。
又根据后面的出错信息:
WARN [JBossJSFConfigureListener] MyFaces JSF implementation found! This version of JBoss AS ships with the java.net implementation of JSF. There are known issues when mixing JSF implementations. This warning does not apply to MyFaces component libraries such as Tomahawk. However, myfaces-impl.jar and myfaces-api.jar should not be used without disabling the built-in JSF implementation. See the JBoss wiki for more details.
这已经很明显就是在说不能同时使用两个JSF实现了,然后如何禁用built-inJSF实现来使用Myfaces还不知道,目前最好的办法就是直接使用SUN的实现吧,反正对于初学者的我来说,应该还用不到什么MyFaces特殊的东西。
