Spark提交无法找到类(ClassNotFoundException)

时间:2019-07-05 19:21:51

标签: java apache-spark jar

我尝试使用脚本中的以下代码在文件夹中运行Main类:

spark-shell --class com.navercorp.Main /target/node2vec-0.0.1-SNAPSHOT.jar --cmd node2vec  ../graph/karate.edgelist --output ../walk/walk.txt 

但是会引发错误:

19/07/05 14:39:20 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
19/07/05 14:39:20 WARN deploy.SparkSubmit$$anon$2: Failed to load com.navercorp.Main.
java.lang.ClassNotFoundException: com.navercorp.Main
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.apache.spark.util.Utils$.classForName(Utils.scala:238)
        at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:810)
        at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:167)
        at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:195)
        at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)
        at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:924)
        at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:933)
        at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

我的文件夹中有jar文件,结构如下: enter image description here

我还附加了jar文件的结构:

META-INF/MANIFEST.MF
log4j2.properties
com/
com/navercorp/
com/navercorp/Node2vec$.class
com/navercorp/Main$Params$$typecreator1$1.class
com/navercorp/Main$$anon$1$$anonfun$11.class
com/navercorp/Word2vec$.class
com/navercorp/Main$$anon$1$$anonfun$8.class
com/navercorp/Node2vec$$anonfun$randomWalk$1$$anonfun$8.class
com/navercorp/Node2vec$$anonfun$indexingGraph$4.class
com/navercorp/Node2vec$$anonfun$initTransitionProb$1.class
com/navercorp/Main$.class
com/navercorp/Node2vec$$anonfun$loadNode2Id$1.class
com/navercorp/Node2vec$$anonfun$14.class
com/navercorp/Node2vec$$anonfun$readIndexedGraph$2$$anonfun$1.class

有人可以给我建议来连接Main class吗?

2 个答案:

答案 0 :(得分:0)

这只是一个猜测,但是我认为当您打算使用相对路径时,您不小心为.jar文件使用了绝对路径。

尝试 spark-shell --class com.navercorp.Main target/node2vec-0.0.1-SNAPSHOT.jar --cmd node2vec ../graph/karate.edgelist --output ../walk/walk.txt

代替spark-shell --class com.navercorp.Main /target/node2vec-0.0.1-SNAPSHOT.jar --cmd node2vec ../graph/karate.edgelist --output ../walk/walk.txt

答案 1 :(得分:0)

能否请您查看下面的链接以进行参考检查: https://spark.apache.org/docs/latest/quick-start.html#self-contained-applications