javax.xml.stream.XMLStreamException:[row,col] 处的 ParseError:jboss-web.xml 中的 [11,3]

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[11,3] in jboss-web.xml

我正在使用 Java 1.6 和 JBoss EAP 6.1。

我的应用程序 运行s 在 JBoss 5.1 上,但是当我尝试 运行 我在 JBoss 6.1 上的应用程序时,我收到此错误:

javax.xml.stream.XMLStreamException: ParseError at [row,col]:[11,3] in jboss-web.xml

JBoss的日志:

00:06:52,823 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "MyApplication-0.0.1-SNAPSHOT.war" (runtime-name: "MyApplication-0.0.1-SNAPSHOT.war")
00:06:54,743 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."MyApplication-0.0.1-SNAPSHOT.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."MyApplication-0.0.1-SNAPSHOT.war".PARSE: JBAS018733: Failed to process phase PARSE of deployment "MyApplication-0.0.1-SNAPSHOT.war"

Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS018014: Failed to parse XML descriptor "/content/MyApplication-0.0.1-SNAPSHOT.war/WEB-INF/jboss-web.xml" at [11,3]
        at org.jboss.as.web.deployment.JBossWebParsingDeploymentProcessor.deploy(JBossWebParsingDeploymentProcessor.java:79)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120) [jboss-as-server-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8]
        ... 5 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[11,3]
Message: Unexpected element 'class-loading' encountered
        at org.jboss.metadata.parser.util.MetaDataElementParser.unexpectedElement(MetaDataElementParser.java:109)
        at org.jboss.metadata.parser.jbossweb.JBossWebMetaDataParser.parse(JBossWebMetaDataParser.java:206)
        at org.jboss.as.web.deployment.JBossWebParsingDeploymentProcessor.deploy(JBossWebParsingDeploymentProcessor.java:71)
        ... 6 more

00:06:54,748 ERROR [org.jboss.as.server] (HttpManagementService-threads - 8) JBAS015870: Deploy of deployment "MyApplication-0.0.1-SNAPSHOT.war" was rolled back with the following failure message: 
{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"MyApplication-0.0.1-SNAPSHOT.war\".PARSE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"MyApplication-0.0.1-SNAPSHOT.war\".PARSE: JBAS018733: Failed to process phase PARSE of deployment \"MyApplication-0.0.1-SNAPSHOT.war\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS018014: Failed to parse XML descriptor \"/content/MyApplication-0.0.1-SNAPSHOT.war/WEB-INF/jboss-web.xml\" at [11,3]
    Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[11,3]
Message: Unexpected element 'class-loading' encountered"}}
00:06:54,867 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment MyApplication-0.0.1-SNAPSHOT.war (runtime-name: MyApplication-0.0.1-SNAPSHOT.war) in 118ms

我在 jboss-web.xml 中遇到此异常:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>

    <!--   <context-root>MyApplication</context-root>
    <class-loading java2ClassLoadingCompliance="false">
        <loader-repository>com.globalss:loader=MyApplication.war
            <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
        </loader-repository> 
    </class-loading>-->

    <class-loading java2ClassLoadingCompliance="false">
        <loader-repository>
            org.myapp:loader=MyApplication.war
            <loader-repository-config>java2ParentDelegation=false
            </loader-repository-config>
       </loader-repository>
    </class-loading>
    <resource-ref>
        <res-ref-name>database</res-ref-name>
        <jndi-name>java:/database</jndi-name>
    </resource-ref>
    <resource-ref>
        <res-ref-name>dataSource</res-ref-name>
        <jndi-name>java:/dataSource</jndi-name>
    </resource-ref>
</jboss-web>

为什么会出现此错误?

出现此错误的根本原因是什么?

我们如何解决这个错误?

根据this JBoss's community thread, the error is occurring because the tag class-loading is no longer present on JBoss EAP 6.X (JBoss AS 7.X) jboss-web.xml schema

标签不再存在的原因是因为

Class loading has changed from hierarchical to modular in AS7. (...) The behaviour that this provokes in EAP 5 is now the default class-loading behaviour in AS 7.

解法通过评论

the <class-loading> element in jboss-web.xml, since it is no longer necessary.