Moh*_*aie 5 java amazon-ec2 apache-httpclient-4.x apache-spark
我正在使用Apache Spark开发Java应用程序.我用这个版本:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.2.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在我的代码中,存在过渡依赖:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我将我的应用程序打包到一个JAR文件中.使用时在EC2实例上部署它时spark-submit,我收到此错误.
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheConnectionManagerFactory.java:87)
at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:65)
at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:58)
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:50)
at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:38)
Run Code Online (Sandbox Code Playgroud)
此错误清楚地表明SparkSubmit已加载相同Apache httpclient库的旧版本,因此出现此冲突.
解决这个问题的好方法是什么?
出于某种原因,我不能在我的Java代码上升级Spark.但是,我可以轻松地使用EC2群集.是否可以在具有更高版本的1.6.1版本的集群上部署我的Java代码?
正如你在帖子中所说,Spark正在加载旧版本的httpclient.解决方案是使用Maven的relocation工具来制作一个整洁的无冲突项目.
以下是如何在pom.xml文件中使用它的示例:
<project>
<!-- Your project definition here, with the groupId, artifactId, and it's dependencies -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.apache.http.client</pattern>
<shadedPattern>shaded.org.apache.http.client</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
这会将所有文件从移动org.apache.http.client到shaded.org.apache.http.client,解决冲突.
原帖:
如果这只是传递依赖的问题,您可以将其添加到spark-core依赖项中以排除Spark使用的HttpClient:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.2.2</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
</exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我还在您的依赖项中添加了scopeas provided,因为它将由您的群集提供.
然而,这可能会破坏Spark的内部行为.如果在执行此操作后仍然出现错误,您可以尝试使用Maven的relocation工具来生成一个整洁的无冲突项目.
关于无法升级Spark版本的事实,你是否使用了mvnrepository中的这个依赖声明?
Spark向后兼容,在具有更高版本的群集上部署作业应该没有任何问题.
| 归档时间: |
|
| 查看次数: |
3966 次 |
| 最近记录: |