spark submit add multiple jars in classpath

2019-01-09 09:01发布

I am trying to run a spark program where i have multiple jar files, if I had only one jar I am not able run. I want to add both the jar files which are in same location. I have tried the below but it shows a dependency error

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

How can i add another jar file which is in the same directory?

I want add /usr/lib/spark/assembly/lib/hive-serde.jar.

7条回答
劫难
2楼-- · 2019-01-09 09:02

Just use the --jars parameter. Spark will share those jars (comma-separated) with the executors.

查看更多
Rolldiameter
3楼-- · 2019-01-09 09:04

Specifying full path for all additional jars works.

./bin/spark-submit --class "SparkTest" --master local[*] --jars /fullpath/first.jar,/fullpath/second.jar /fullpath/your-program.jar

Or add jars in conf/spark-defaults.conf by adding lines like:

spark.driver.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
spark.executor.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
查看更多
三岁会撩人
4楼-- · 2019-01-09 09:05

You can use * for import all jars into a folder when adding in conf/spark-defaults.conf .

spark.driver.extraClassPath /fullpath/*
spark.executor.extraClassPath /fullpath/*
查看更多
5楼-- · 2019-01-09 09:14

For --driver-class-path option you can use : as delimeter to pass multiple jars. Below is the example with spark-shell command but I guess the same should work with spark-submit as well

    spark-shell --driver-class-path /path/to/example.jar:/path/to/another.jar

Spark version: 2.2.0

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-09 09:20

I was trying to connect to mysql from the python code that was executed using spark-submit.

I was using HDP sandbox that was using Ambari. Tried lot of options such as --jars, --driver-class-path, etc, but none worked.

Solution

Copy the jar in /usr/local/miniconda/lib/python2.7/site-packages/pyspark/jars/

As of now I'm not sure if it's a solution or a quick hack, but since I'm working on POC so it kind of works for me.

查看更多
Melony?
7楼-- · 2019-01-09 09:22

For me --jars option always works but it's too verbose. To save some typing, you can put all jars in a directory say 'myJars' and then use this command to submit:

spark-submit --master local[*] --jars "/path/to/myJars/*.jar"    --class <ClassName> <application_jar_name>.jar arg1 arg2
查看更多
登录 后发表回答