我想提交一個作業在Cloudera CDH 5.8.0虛擬框中激發,並且我使用的是json庫,並且我還使用了maven-shade插件包括依賴於jar文件,下面是我的POM:如何解決與Cloudera CDH 5.8.0的Spark庫衝突虛擬框
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>spark</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>1.5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<finalName>uber-${project.artifactId}-${project.version}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</project>
提交的命令是:
spark-submit --class com.example.spark.SparkParser --master local[*] uber-spark-0.0.1-SNAPSHOT.jar
而且我不斷收到以下異常:
Exception in thread "main" java.lang.NoSuchMethodError:
org.json.JSONTokener.<init>(Ljava/io/InputStream;)
我發現了一個小下面的代碼,它可以告訴從庫中的類加載:
ClassLoader classloader = org.json.JSONTokener.class.getClassLoader();
URL res = classloader.getResource("org/json/JSONTokener.class");
String path = res.getPath();
System.out.println("Core JSONTokener came from " + path);
和輸出是如下:
Core JSONTokener came from file:/usr/lib/hive/lib/hive-exec-1.1.0-cdh5.8.0.jar!/org/json/JSONTokener.class
我可以在虛擬的本地查找文件CDH盒如下:
[[email protected] ~]$ ls -l /usr/lib/hive/lib/hive-exec-1.1.0-cdh5.8.0.jar
-rw-r--r-- 1 root root 19306194 Jun 16 2016 /usr/lib/hive/lib/hive-exec-1.1.0-cdh5.8.0.jar
我甚至試圖使JSON庫爲「提供」從我的jar文件中排除,但仍是同樣的錯誤要麼。
我試圖刪除名爲當地的jar文件: /usr/lib/hive/lib/hive-exec-1.1.0-cdh5.8.0.jar 我的代碼工作正常,但我不知道這是正確的解決方案,如果刪除這個庫會以某種方式傷害cloudera。
那麼,我怎麼能告訴spark不使用這個本地jar文件,並使用我的'uber-spark-0.0.1-SNAPSHOT.jar'文件中包含的那個?