我试图在Amazon中运行一个Flink应用程序。我使用的是最新版本,所以EMR为6.7.0,Flink为1.14.2。
我使用Maven将我的应用程序和依赖关系构建到jar中,以便运行EMR。当我在EMR中作为步骤运行Flink应用程序时,我会得到以下错误
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.math3.stat.descriptive.rank.Percentile.withNaNStrategy(Lorg/apache/commons/math3/stat/ranking/NaNStrategy;)Lorg/apache/commons/math3/stat/descriptive/rank/Percentile;
at MyFlinkApp.main(MyFlinkApp.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.hadoop.util.RunJar.run(RunJar.java:323)
at org.apache.hadoop.util.RunJar.main(RunJar.java:236)
我添加了一些日志记录,以了解commons 3的版本是什么,它是百分位数类的来源,也是3.1.1版本,正如它所说的,它不包括它试图调用的withNaNStrategy方法。
我的假设是,我可以使用较新版本的commons 3运行,其中添加了该方法。在我的pom.xml中,我将commons 3的版本指定为3.6.1,我可以验证它是构建在我的jar中的。
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
我仍然得到相同的错误,我可以看到,它仍然在使用3.1.1版本的插件。这是从哪里来的,这是从电子病历本身吗?我怎么才能绕过这一切?
如果有帮助的话,我可以从pom中提供我的全部依赖项列表。
发布于 2022-08-03 07:38:00
不幸的是,您遇到了一个非常常见的问题,即在Apache或Apache上运行应用程序(在集群上)。
有两种不同的类路径:
commons-math3:3.1.1
作为hadoop-common
的传递依赖项。commons-math3:3.6.1
的应用程序类路径如果您在集群上运行Flink应用程序,您的应用程序类路径将被附加到现有的系统类路径中,并且第一个将获胜。没有更多的依赖解决方案可以确定应该有效地使用哪个版本。另外,通常情况下,当执行程序启动时,应用程序类路径还不可用.
如果在本地模式下运行,所有的东西通常都会正常工作--至少在大多数情况下--因为所有依赖项都被解析为一个类路径。
解决这一问题的方法是使用Maven Shade插件对冲突库的包进行遮挡(也称为重命名)。使用这个插件,您可以构建一个包含不同位置的冲突类的uber jar,这样它们就可以独立地用于集群中已经存在的类。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>allinone</shadedClassifierName>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.apache.commons.math3</pattern>
<shadedPattern>org.apache.commons.math3_1_1</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
https://stackoverflow.com/questions/73211149
复制相似问题