spark submit在classpath中添加多个jar

Avi*_*h S 35 classpath submit apache-spark

我正在尝试运行一个火花程序,其中我有多个jar文件,如果我只有一个jar我无法运行.我想添加位于相同位置的jar文件.我已尝试过以下但它显示了依赖性错误

spark-submit \
  --class "max" maxjar.jar Book1.csv test \
  --driver-class-path /usr/lib/spark/assembly/lib/hive-common-0.13.1-cdh?5.3.0.jar
Run Code Online (Sandbox Code Playgroud)

如何添加另一个位于同一目录下的jar文件?

我想加/usr/lib/spark/assembly/lib/hive-serde.jar.

pze*_*vic 31

只需使用--jars参数.Spark将与执行程序共享这些jar(以逗号分隔).

  • 我尝试用逗号分隔的spark-submit --class“ max” maxjar.jar Book1.csv测试/usr/lib/spark/assembly/lib/hive-common-0.13.1-cdh5.3.0.jar,hive-serde.jar 。但是它都没有读出两个罐子。我在org / apache / hadoop / hive / conf / HiveConf中收到此错误 (2认同)
  • 我的意思是,像这样使用它:spark-submit --master master_url --jars jar1,jar2 --class classname application_jar (2认同)

小智 29

指定所有其他jar的完整路径.

./bin/spark-submit --class "SparkTest" --master local[*] --jars /fullpath/first.jar,/fullpath/second.jar /fullpath/your-program.jar
Run Code Online (Sandbox Code Playgroud)

或者通过添加如下行来在conf/spark-defaults.conf中添加jar:

spark.driver.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
spark.executor.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
Run Code Online (Sandbox Code Playgroud)


小智 13

在conf/spark-defaults.conf中添加时,可以使用*将所有jar导入到文件夹中.

spark.driver.extraClassPath /fullpath/*
spark.executor.extraClassPath /fullpath/*
Run Code Online (Sandbox Code Playgroud)


Ayu*_*yan 5

我试图从使用spark-submit.

我使用的是使用 Ambari 的 HDP 沙箱。试过很多选择,如--jars--driver-class-path等,但没有奏效。

解决方案

将罐子复制进去 /usr/local/miniconda/lib/python2.7/site-packages/pyspark/jars/

截至目前,我不确定这是一个解决方案还是一个快速破解,但由于我正在研究 POC,所以它对我有用。


Bin*_*ati 5

在 Spark 2.3 中,您只需要设置 --jars 选项。文件路径应该以方案开头,file:///<absolute path to the jars> 例如:file:////home/hadoop/spark/externaljsrs/*file:////home/hadoop/spark/externaljars/abc.jar,file:////home/hadoop/spark/externaljars/def.jar


Nan*_*esh 5

传递以to分隔的文件--jars路径。jar,spark-submit

以供参考:

--driver-class-path is used to mention "extra" jars to add to the "driver" of the spark job

--driver-library-path is used to "change" the default library path for the jars needed for the spark driver

--driver-class-path will only push the jars to the driver machine. If you want to send the jars to "executors", you need to use --jars
Run Code Online (Sandbox Code Playgroud)

并以编程方式设置 jars,设置以下配置: spark.yarn.dist.jars使用逗号分隔的 jars 列表。

例如:

from pyspark.sql import SparkSession

spark = SparkSession \
        .builder \
        .appName("Spark config example") \
        .config("spark.yarn.dist.jars", "<path-to-jar/test1.jar>,<path-to-jar/test2.jar>") \
        .getOrCreate()
Run Code Online (Sandbox Code Playgroud)