spark依赖项的ClassNotFoundException

时间:2016-01-18 14:02:29

标签: java maven intellij-idea apache-spark

我在某个spark项目中添加了第三方jar。问题是intelliJ干净地编译和运行代码。但是,当我使用

在集群中提交它时
./bin/spark-submit --master yarn --class myClass my.jar input output_files 

我得到了

java.lang.NoClassDefFoundError: gov/nih/nlm/nls/metamap/MetaMapApi
    at metamap.MetaProcess$2.call(MetaProcess.java:46)
    at metamap.MetaProcess$2.call(MetaProcess.java:28)
    at org.apache.spark.api.java.JavaPairRDD$$anonfun$toScalaFunction$1.apply(JavaPairRDD.scala:1027)
    at org.apache.spark.rdd.PairRDDFunctions$$anonfun$mapValues$1$$anonfun$apply$41$$anonfun$apply$42.apply(PairRDDFunctions.scala:700)
    at org.apache.spark.rdd.PairRDDFunctions$$anonfun$mapValues$1$$anonfun$apply$41$$anonfun$apply$42.apply(PairRDDFunctions.scala:700)
    at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
    at scala.collection.Iterator$$anon$11.next(Iterator.scala:328)
    at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13$$anonfun$apply$6.apply$mcV$sp(PairRDDFunctions.scala:1109)
    at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13$$anonfun$apply$6.apply(PairRDDFunctions.scala:1108)
    at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13$$anonfun$apply$6.apply(PairRDDFunctions.scala:1108)
    at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1285)
    at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13.apply(PairRDDFunctions.scala:1116)
    at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$13.apply(PairRDDFunctions.scala:1095)
    at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:63)
    at org.apache.spark.scheduler.Task.run(Task.scala:70)
    at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:213)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: gov.nih.nlm.nls.metamap.MetaMapApi
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

我尝试将jar的第三方库添加到setJar SparkContext实例,但它没有用。然后我将依赖添加为maven,但它也没有多大帮助。最后,我尝试指定--jars命令行选项,但没有成功。有人可以帮忙吗

1 个答案:

答案 0 :(得分:1)

以下是可用的选项以及命令: -

  1. 创建一个包含所有依赖项的胖jar文件,并将其与spark-submit命令一起使用,如下所示: -

    ./bin/spark-submit --class <MAIN-CLASS> --master yarn --deploy-mode cluster <PATH TO APP JAR FIlE>
    
  2. 将jar文件复制到 http:// FTP:// HDFS:// ,然后利用SparkConf.setJars并指定完整路径,例如 - SparkConf.setJars(Array("http://mydir/one.jar")),最后以相同的方式使用spark-submit命令,不做任何更改: -

    ./bin/spark-submit --class <MAIN-CLASS> --master yarn --deploy-mode cluster <PATH TO APP JAR FILE>
    
  3. 将jar文件复制到 http:// FTP:// HDFS:// ,然后使用使用 - jars 选项 spark-submit 命令: -

    ./bin/spark-submit --class <MAIN-CLASS> --jars <http://mydir/one.jar,http://mydir/two.jar> --master yarn --deploy-mode cluster <PATH TO APP JAR FILE>
    
  4. SPARK_HOME / spark-default.conf 文件中指定变量spark.driver.extraClassPathspark.executor.extraClassPath,并将值作为dpendent jar文件的完整路径,然后使用与#1

  5. 中使用的 spark-submit 命令相同

    根据用例,任何一个选项都可以使用。如果没有工作,那么您可能需要重新检查提供的 spark-submit 命令的依赖项

    有关更多信息,请参阅submitting the applcations