org.xml.sax.SAXException:错误处理/META-INF/primefaces-p.taglib.xml

时间:2012-09-29 13:13:32

标签: jsf primefaces facelets

我正在尝试制作一个简单的JSF(基于PrimeFaces)应用程序运行。

主页非常简单:

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"

        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui">
<head>
<title>Hello World</title>
</head>
<body>
        <p:editor />
</body>
</html>

当我

  1. 尝试使用mvn jetty:run
  2. 运行Web应用程序
  3. 在浏览器中打开页面
  4. 我收到以下错误:

    java.io.IOException: Error parsing [jar:file:/C:/Users/DP118M/.m2/repository/org/primefaces/primefaces/3.4.1/primefaces-3.4.1.jar!/META-INF/primefaces-p.taglib.xml]:
            at com.sun.facelets.compiler.TagLibraryConfig.create(TagLibraryConfig.java:410)
            at com.sun.facelets.compiler.TagLibraryConfig.loadImplicit(TagLibraryConfig.java:431)
            at com.sun.facelets.compiler.Compiler.initialize(Compiler.java:87)
            at com.sun.facelets.compiler.Compiler.compile(Compiler.java:104)
            at com.sun.facelets.impl.DefaultFaceletFactory.createFacelet(DefaultFaceletFactory.java:197)
            at com.sun.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:144)
            at com.sun.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:95)
            at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:517)
            at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
            at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:115)
            at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:241)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:199)
            at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
            at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
            at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:341)
            at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
            at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
            at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
            at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
            at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
            at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
            at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
            at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
            at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
            at org.mortbay.jetty.Server.handle(Server.java:326)
            at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
            at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
            at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
            at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
            at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
            at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
            at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
    Caused by: org.xml.sax.SAXException: Error Handling [jar:file:/C:/Users/DP118M/.
    m2/repository/org/primefaces/primefaces/3.4.1/primefaces-3.4.1.jar!/META-INF/primefaces-p.taglib.xml@5,17]
            at com.sun.facelets.compiler.TagLibraryConfig$LibraryHandler.error(TagLibraryConfig.java:376)
            at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
            at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
            at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
            at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.rootElementSpecified(XMLDTDValidator.java:1621)
            at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1900)
            at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:764)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1363)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1318)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:922)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
            at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
            at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
            at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
            at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
            at com.sun.facelets.compiler.TagLibraryConfig.create(TagLibraryConfig.java:407)
            ... 31 more
    

    代码位于https://dl.dropbox.com/u/11776689/2012_09_29_primefaces_app.zip

    如何解决此错误?

    更新1:

    根据BalusC的建议,我注释掉了依赖

    <dependency>
        groupId>com.sun.facelets</groupId>
        <artifactId>jsf-facelets</artifactId>
        <version>1.1.14</version>
    </dependency>
    
    pom.xml中的

    代码中没有faces-config.xml(至少,我找不到它)。

    当我运行应用程序时,我收到另一个错误:

    FATAL: Class com.sun.facelets.FaceletViewHandler not found
    java.lang.ClassNotFoundException: com.sun.facelets.FaceletViewHandler
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at org.codehaus.classworlds.RealmClassLoader.loadClassDirect(RealmClassLoader.java:195)
            at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:255)
            at org.codehaus.classworlds.DefaultClassRealm.loadClass(DefaultClassRealm.java:274)
            at org.codehaus.classworlds.RealmClassLoader.loadClass(RealmClassLoader.java:214)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
            at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:401)
            at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:363)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:247)
            at org.apache.myfaces.shared.util.ClassUtils.classForName(ClassUtils.java:199)
            at org.apache.myfaces.shared.util.ClassUtils.simpleClassForName(ClassUtils.java:218)
            at org.apache.myfaces.shared.util.ClassUtils.buildApplicationObject(ClassUtils.java:515)
            at org.apache.myfaces.shared.util.ClassUtils.buildApplicationObject(ClassUtils.java:487)
            at org.apache.myfaces.config.FacesConfigurator.configureApplication(FacesConfigurator.java:551)
            at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:416)
            at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:338)
            at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:73)
            at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:140)
            at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:111)
            at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
            at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
            at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
            at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
            at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
            at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:115)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
            at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
            at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
            at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
            at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
            at org.mortbay.jetty.Server.doStart(Server.java:224)
            at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
            at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
            at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:441)
            at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:383)
            at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
            at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
            at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
            at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
            at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            ...
    

    这个FaceletViewHandler在哪里使用?

    以下是更新后的代码:https://dl.dropbox.com/u/11776689/2012_09_29_primefaces_app2.zip

    解决方案:

    1)备份项目。

    2)按照http://myfaces.apache.org/build-tools/archetypes/myfaces-archetype-helloworld20/index.html

    解释,在Maven中重新创建它
    1. 运行命令mvn archetype:generate -DarchetypeCatalog=http://myfaces.apache.org
    2. 从可用选项列表中选择myfaces-archetype-helloworld20
    3. 3)将PrimeFaces存储库和依赖项添加到pom.xml

1 个答案:

答案 0 :(得分:4)

堆栈跟踪中com.sun.facelets.*的存在告诉您在webapp的运行时类路径中有来自Facelets 1.x的jsf-facelets JAR文件(并且您已明确注册其ViewHandler在webapp的faces-config.xml中!)。

这是不对的。从JSF 2.0开始,Facelets已经捆绑在JSF API / impl库中(已移至com.sun.faces.facelets.*包)。 jsf-facelets移除 <view-handler>依赖关系及其faces-config.xml。可以使用 FacesServlet中的web.xml创建一个干净的JSF 2.0 / Facelets设置(甚至没有上下文参数和所有其他混乱)和空faces-config.xml

此异常的原因基本上归结为Facelets 1.x无法识别Facelets 2.0兼容的标记库(如PrimeFaces&gt; = 2.0)。

开始使用JSF 2.0时,请确保您没有查看JSF 1.x书籍/资源/示例。从JSF 2.x开始,很多东西都被改变了,并且做了不同的事情。 Start at our JSF wiki page