我遇到了一系列关于公理和骡子的问题,在这里可以找到一个背景:
https://stackoverflow.com/questions/34164577/classloader-overrides-not-working-in-mule
正如对上一期的评论中提到的,由于冲突的jars,我能够使用maven shade覆盖mule中axiom的包名。Mule在服务器中加载axiom和axiom的版本。我在连接器中使用了axiom和axiom的不同版本。(连接器在任意点演播室外进行精细测试)
使用maven树荫,我重命名:
org.apache.axiom至
org.apache.1.2.14.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)我相信这是因为将axiom包重新命名为maven shade。我的maven的影子是这样的:
<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包的一个实例。为了解决这个问题,我认为我只需要重命名:
org.apache.axiom.om.impl.dom.factory.OMDOMMetaFactoryLoader至
org.apache.1.2.14.axiom.om.impl.dom.factory.OMDOMMetaFactoryLoader我找到了一个axiom.xml的例子:
http://grepcode.com/file/repo1.maven.org/maven2/org.apache.ws.commons.axiom/axiom-impl/1.2.13/META-INF/axiom.xml/
我找不到关于这个文件的任何文档,但我看到了源代码中使用它的位置。我想我可以重写:
<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>但那没有效果。是否有一种方法可以重写doom加载程序类名?
发布于 2015-12-11 22:30:21
要自动执行必要的转换,可以使用以下配置:
<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快照存储库添加到POM中(因为还没有包含变化的发行版来完成这项工作):
<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>请注意,shade-axiom-xml版本1.2.17-SNAPSHOT在Axiom1.2.14中应该可以正常工作,也就是说,您不需要更改所依赖的Axiom库的版本。
另外,不要忘记,由于您使用的是Axis2,而Axis2依赖于公理,所以您需要在工件集中包含所有Axis2 JAR。
发布于 2018-03-14 10:04:35
当发生这种情况时,可以尝试从阴影中排除有问题的类(应用程序正在转换到的类,即在您的情况下,您应该排除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>https://stackoverflow.com/questions/34229040
复制相似问题