Mule Axiom实现加载程序覆盖

Mule Axiom实现加载程序覆盖,mule,maven-shade-plugin,axiom,Mule,Maven Shade Plugin,Axiom,我遇到了一系列问题,可以在这里找到背景: 正如在上一期的评论中提到的,由于JAR冲突,我能够在mule中使用maven shade覆盖axiom api的包名。Mule在服务器中加载axiom api和axiom impl的版本。我在连接器中使用了不同版本的axiom api和axiom dom。(连接器可在anypoint studio外进行精细测试) 使用maven shade,我重命名: org.apache.axiom 到 这解决了由于jar版本冲突而找不到方法的原始问题。现在我遇到

我遇到了一系列问题,可以在这里找到背景:

正如在上一期的评论中提到的,由于JAR冲突,我能够在mule中使用maven shade覆盖axiom api的包名。Mule在服务器中加载axiom api和axiom impl的版本。我在连接器中使用了不同版本的axiom api和axiom dom。(连接器可在anypoint studio外进行精细测试)

使用maven shade,我重命名:

org.apache.axiom

这解决了由于jar版本冲突而找不到方法的原始问题。现在我遇到的问题是:

org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactoryLoader cannot be cast to org.apache.1.2.14.axiom.locator.loader.OMMetaFactoryLoader (java.lang.ClassCastException)   org.apache.1.2.14.axiom.locator.ImplementationFactory:133 (null)
我相信这是因为用maven shade重命名了axiom api的包。我的maven shade配置如下所示:

<configuration>
                    <artifactSet>
                        <includes>
                            <include>org.apache.ws.commons.axiom:*</include>
                        </includes>
                    </artifactSet>
                    <relocations>
                        <relocation>
                            <pattern>org.apache.axiom</pattern>
                            <shadedPattern>org.apache.1.2.14.axiom</shadedPattern>
                        </relocation>
                    </relocations>
                </configuration>

我找到了axiom.xml的一个示例:

我找不到这个文件的任何文档,但我知道它在源代码中的使用位置。我想我可以重写:

<implementation loader="org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactoryLoader" name="doom">
              <feature name="dom" priority="100"/>
       </implementation>



但这没有效果。是否有方法覆盖doom loader类名?

要自动执行必要的转换,可以使用以下配置:

    <plugins>
        <plugin>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>org.apache.ws.commons.axiom:*</include>
                            </includes>
                        </artifactSet>
                        <transformers>
                            <transformer implementation="org.apache.axiom.buildutils.shade.axiomxml.AxiomXmlResourceTransformer" />
                        </transformers>
                        <relocations>
                            <relocation>
                                <pattern>org.apache.axiom</pattern>
                                <shadedPattern>org.apache.1.2.14.axiom</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.ws.commons.axiom</groupId>
                    <artifactId>shade-axiom-xml</artifactId>
                    <version>1.2.17-SNAPSHOT</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>

这使这项工作得以开展):


apache.snapshots
Apache快照存储库
http://repository.apache.org/snapshots
假的
请注意,
shade axiom xml
version
1.2.17-SNAPSHOT
应该可以与axiom 1.2.14配合使用,也就是说,您不需要更改所依赖的axiom库的版本


另外,不要忘记,因为您使用的是Axis2,Axis2依赖于Axiom,所以您需要在工件集中包含所有Axis2 JAR。

当发生此类ClassCastException时,可以尝试从着色中排除有问题的类(应用程序正在对其进行强制转换,即在您的情况下,您应该排除org.apache.axiom.locator.loader.OMMetaFactoryLoader)

您可以通过以下方式执行此操作:

<relocations>
    <relocation>
        <pattern>org.apache.axiom</pattern>
        <shadedPattern>org.apache.1.2.14.axiom</shadedPattern>
        <excludes>
            <exclude>org.apache.axiom.locator.loader.OMMetaFactoryLoader</exclude>
        </excludes>
    </relocation>
</relocations>

org.apache.axiom
org.apache.1.2.14.axiom
org.apache.axiom.locator.loader.OMMetaFactoryLoader

Hey Andreas,很抱歉响应延迟。因此,当我使用您的插件定义时,我返回到最初的错误“geMetaFactory(NoSuchMethodError)”,我一定是做错了什么,但复制粘贴了您的插件定义,它不再试图加载“org.apache.1.2.14.axiom”,它只是“org.apache.axiom”因此,它再次使用旧版本,没有任何内容被着色。当您说没有任何内容被着色时,您是否通过检查maven shade插件生成的JAR来确认?我查看了错误中的strack跟踪。前面的错误,堆栈跟踪提到:org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactoryLoader不能被强制转换对于org.apache.1.2.14.axiom.locator.loader.OMMetaFactoryLoader(java.lang.ClassCastException)org.apache.1.2.14.axiom.locator.ImplementationFactory:133(null),您可以看到包名表示通过着色创建的内容。具体来说,是对“1.2.14”的引用。新错误不再包含“1.2.14”,只包含“org.apache.axiom”。错误在于使用旧版本时没有这种方法。这很公平。你选择不回答我的问题,所以我猜你当时不需要我的帮助。我想我确实回答了你的问题。我告诉你我是如何得出结论的。我真的很感谢你的帮助,我不确定我是如何得罪了你请接受我的回答,但我道歉。
<implementation loader="org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactoryLoader" name="doom">
              <feature name="dom" priority="100"/>
       </implementation>
<implementation loader="org.apache.1.2.14.axiom.om.impl.dom.factory.OMDOMMetaFactoryLoader" name="doom">
              <feature name="dom" priority="100"/>
       </implementation>
    <plugins>
        <plugin>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <artifactSet>
                            <includes>
                                <include>org.apache.ws.commons.axiom:*</include>
                            </includes>
                        </artifactSet>
                        <transformers>
                            <transformer implementation="org.apache.axiom.buildutils.shade.axiomxml.AxiomXmlResourceTransformer" />
                        </transformers>
                        <relocations>
                            <relocation>
                                <pattern>org.apache.axiom</pattern>
                                <shadedPattern>org.apache.1.2.14.axiom</shadedPattern>
                            </relocation>
                        </relocations>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.ws.commons.axiom</groupId>
                    <artifactId>shade-axiom-xml</artifactId>
                    <version>1.2.17-SNAPSHOT</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
    <repositories>
        <repository>
            <id>apache.snapshots</id>
            <name>Apache Snapshot Repository</name>
            <url>http://repository.apache.org/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>
<relocations>
    <relocation>
        <pattern>org.apache.axiom</pattern>
        <shadedPattern>org.apache.1.2.14.axiom</shadedPattern>
        <excludes>
            <exclude>org.apache.axiom.locator.loader.OMMetaFactoryLoader</exclude>
        </excludes>
    </relocation>
</relocations>