spark 提交在类路径中添加多个 jar
spark submit add multiple jars in classpath
我正在尝试 运行 一个有多个 jar 文件的 spark 程序,如果我只有一个 jar,我就无法 运行。我想添加位于同一位置的两个 jar 文件。我试过下面的但它显示依赖错误
spark-submit \
--class "max" maxjar.jar Book1.csv test \
--driver-class-path /usr/lib/spark/assembly/lib/hive-common-0.13.1-cdh5.3.0.jar
如何在同一目录中添加另一个 jar 文件?
我要添加 /usr/lib/spark/assembly/lib/hive-serde.jar
.
只需使用--jars
参数。 Spark 将与执行者共享这些罐子(以逗号分隔)。
指定所有其他 jar 的完整路径有效。
./bin/spark-submit --class "SparkTest" --master local[*] --jars /fullpath/first.jar,/fullpath/second.jar /fullpath/your-program.jar
或者在 conf/spark-defaults.conf 中添加 jar,方法是添加如下行:
spark.driver.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
spark.executor.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
在conf/spark-defaults.conf 中添加时,您可以使用 * 将所有 jar 导入文件夹。
spark.driver.extraClassPath /fullpath/*
spark.executor.extraClassPath /fullpath/*
我试图从使用 spark-submit
执行的 python 代码连接到 mysql。
我使用的是 HDP 沙箱,它使用的是 Ambari。尝试了很多选项,例如 --jars
、--driver-class-path
等,但 none 有效。
解决方案
复制 /usr/local/miniconda/lib/python2.7/site-packages/pyspark/jars/
中的 jar
截至目前,我不确定它是一个解决方案还是一个快速破解,但由于我正在研究 POC,所以它对我有用。
在 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
对于 --driver-class-path
选项,您可以使用 :
作为分隔符来传递多个 jar。
下面是使用 spark-shell
命令的示例,但我想同样适用于 spark-submit
以及
spark-shell --driver-class-path /path/to/example.jar:/path/to/another.jar
Spark 版本:2.2.0
您可以使用 --jars $(echo /Path/To/Your/Jars/*.jar | tr ' ' ',') 来包含 Jars 的整个文件夹。
所以,
火花提交——classcom.yourClass\
--jars $(echo /Path/To/Your/Jars/*.jar | tr ' ' ',') \
...
如果您使用的是属性文件,您可以在其中添加以下行:
spark.jars=jars/your_jar1.jar,...
假设
<your root from where you run spark-submit>
|
|-jars
|-your_jar1.jar
将 --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
要以编程方式设置 jars,请设置以下配置:
spark.yarn.dist.jars
以逗号分隔的 jar 列表。
例如:
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()
我正在尝试 运行 一个有多个 jar 文件的 spark 程序,如果我只有一个 jar,我就无法 运行。我想添加位于同一位置的两个 jar 文件。我试过下面的但它显示依赖错误
spark-submit \
--class "max" maxjar.jar Book1.csv test \
--driver-class-path /usr/lib/spark/assembly/lib/hive-common-0.13.1-cdh5.3.0.jar
如何在同一目录中添加另一个 jar 文件?
我要添加 /usr/lib/spark/assembly/lib/hive-serde.jar
.
只需使用--jars
参数。 Spark 将与执行者共享这些罐子(以逗号分隔)。
指定所有其他 jar 的完整路径有效。
./bin/spark-submit --class "SparkTest" --master local[*] --jars /fullpath/first.jar,/fullpath/second.jar /fullpath/your-program.jar
或者在 conf/spark-defaults.conf 中添加 jar,方法是添加如下行:
spark.driver.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
spark.executor.extraClassPath /fullpath/firs.jar:/fullpath/second.jar
在conf/spark-defaults.conf 中添加时,您可以使用 * 将所有 jar 导入文件夹。
spark.driver.extraClassPath /fullpath/*
spark.executor.extraClassPath /fullpath/*
我试图从使用 spark-submit
执行的 python 代码连接到 mysql。
我使用的是 HDP 沙箱,它使用的是 Ambari。尝试了很多选项,例如 --jars
、--driver-class-path
等,但 none 有效。
解决方案
复制 /usr/local/miniconda/lib/python2.7/site-packages/pyspark/jars/
截至目前,我不确定它是一个解决方案还是一个快速破解,但由于我正在研究 POC,所以它对我有用。
在 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
对于 --driver-class-path
选项,您可以使用 :
作为分隔符来传递多个 jar。
下面是使用 spark-shell
命令的示例,但我想同样适用于 spark-submit
以及
spark-shell --driver-class-path /path/to/example.jar:/path/to/another.jar
Spark 版本:2.2.0
您可以使用 --jars $(echo /Path/To/Your/Jars/*.jar | tr ' ' ',') 来包含 Jars 的整个文件夹。 所以, 火花提交——classcom.yourClass\ --jars $(echo /Path/To/Your/Jars/*.jar | tr ' ' ',') \ ...
如果您使用的是属性文件,您可以在其中添加以下行:
spark.jars=jars/your_jar1.jar,...
假设
<your root from where you run spark-submit>
|
|-jars
|-your_jar1.jar
将 --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
要以编程方式设置 jars,请设置以下配置:
spark.yarn.dist.jars
以逗号分隔的 jar 列表。
例如:
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()