【问题标题】:Error when deploying to WildFly: "Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"部署到 WildFly 时出错:“原因:java.lang.ClassCastException:org.dom4j.DocumentFactory 无法转换为 org.dom4j.DocumentFactory”
【发布时间】:2019-06-10 13:04:44
【问题描述】:

当我尝试将我的 Java EE 应用程序部署到 WildFly 15.0.1.Final 时,我一直看到此错误。

我看到 org.apache.directory.api::api-all depends on org.apache.servicemix.bundles::org.apache.servicemix.bundles.dom4j,以及后一个依赖 depends onorg.dom4j ::dom4j。另一方面,我的 WildFly 安装在 modules/system/layers/base/org/dom4j/main/ 中有 dom4j-2.1.1.jar

我在 pom.xml 中尝试了各种方法,例如使用 org.apache.servicemix.bundles::org.apache.servicemix.bundles.dom4j 和 org.dom4j::dom4j,排除它们并指定“避免”的范围。没有任何效果。

这是我的 pom.xml 中的 sn-p:

<properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <finalWarName>ldapuserimport</finalWarName>
    </properties>

    <dependencies>
        <!-- Java EE 7 dependency -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.2_spec</artifactId>
            <version>1.0.2.Final</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.annotation</groupId>
            <artifactId>jboss-annotations-api_1.3_spec</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.directory.api</groupId>
            <artifactId>api-all</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.26</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>27.1-jre</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>2.0.1.Final</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </build>

您能建议如何解决这个问题吗?

【问题讨论】:

  • @TechFree 我看到了。我在 pom.xml 中没有休眠依赖项。我尝试添加 jboss-deployment-structure.xml 但这没有帮助。
  • org.jboss.spec.javax.annotation:jboss-annotations-api_1.3_specjavax.persistence:persistence-api 都应标记为&lt;scope&gt;provided&lt;/scope&gt;
  • 我最终删除了这些org.jboss.spec.javax.annotation:jboss-annotations-api_1.3_specjavax.persistence:persistence-api 以及org.jboss.spec.javax.ejb:jboss-ejb-api_3.2_spec,因为它们被证明是不必要的。删除 部分后,该问题意外再次出现。最终解决该问题的方法是从 org.apache.directory.api:api-all 中排除 org.apache.servicemix.bundle:org.apache.servicemix.bundles.dom4j 并添加依赖项 org.dom4j:dom4j(版本 2.1.1)。希望这会对某人有所帮助。

标签: java maven jakarta-ee wildfly


【解决方案1】:

您的一个依赖项具有 dom4j 旧版本,而服务器使用该版本。为你的依赖项尝试这个命令,看看哪个使用旧的 dom4j 版本

mvn dependency:tree -Dverbose -Dincludes=commons-collections

之后,在您的依赖标签中从该依赖中排除 dom4j。

 <exclusions>
        <exclusion>  <!-- declare the exclusion here -->
          <groupId>sample.ProjectB</groupId>
          <artifactId>Project-B</artifactId>
        </exclusion>
      </exclusions> 

或者尝试使用具有dom4j旧版本依赖的较新版本的依赖

【讨论】:

  • 您的命令显示 org.apache.directory.api:api-all 使用 commons-collections:commons-collections。当我运行“mvn dependency:tree -Dverbose -Dincludes=org.dom4j”时,它表明没有任何东西依赖于 org.dom4j。在创建此主题之前,我尝试将 org.dom4j 从 org.apache.directory.api:api-all 中排除,但没有帮助。
【解决方案2】:

我已经通过删除这两行解决了这个问题

<deployments>
</deployments>

在 WildFly 的standalone.xml 中。这个版本的standalone.xml 是从以前安装WildFly 的standalone.xml 创建的,在这种情况下,事情更容易运行,删除除必要部分之外的所有内容(即数据源和驱动程序部分)。

很奇怪。

【讨论】:

    猜你喜欢
    • 2019-03-25
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多