在Submitting Applications in the Spark docs, as of 1.6.0 and earlier ,不清楚如何指定 --jars 参数,因为它显然不是用冒号分隔的类路径,也不是目录扩展。
文档说“包含您的应用程序和所有依赖项的捆绑 jar 的路径。该 URL 必须在集群内部全局可见,例如,hdfs://路径或 file://路径存在于所有节点。”
Question: What are all the options for submitting a classpath with --jars in the spark-submit script in $SPARK_HOME/bin? Anything undocumented that could be submitted as an improvement for docs?
我问是因为今天我测试 --jars 时,我们必须明确提供每个 jar 的路径:
/usr/local/spark/bin/spark-submit --class jpsgcs.thold.PipeLinkageData ---jars=local:/usr/local/spark/jars/groovy-all-2.3.3.jar,local:/usr/local/spark/jars/guava-14.0.1.jar,local:/usr/local/spark/jars/jopt-simple-4.6.jar,local:/usr/local/spark/jars/jpsgcs-core-1.0.8-2.jar,local:/usr/local/spark/jars/jpsgcs-pipe-1.0.6-7.jar /usr/local/spark/jars/thold-0.0.1-1.jar
我们选择在每个 worker 上使用/usr/local/spark/jars 中的所有 jar 预填充集群,似乎如果没有提供 local:/file:/或 hdfs:,则默认为file:/并且驱动程序使 jars 在驱动程序运行的网络服务器上可用。如上所述,我选择了本地。
而且似乎我们不需要将主 jar 放在 --jars 参数中,我还没有测试最后一个参数中是否有其他类(每个文档的应用程序 jar arg,即/usr/local/spark/jars/thold-0.0.1-1.jar) 被运送给工作人员,或者如果我需要将 application-jar 放在 --jars 路径中以获取未以 --class 命名的类以供查看。
(并使用 --deploy-mode 客户端授予 Spark 独立模式,您还必须在每个工作人员上放置一份驱动程序副本,但您事先不知道哪个工作人员将运行该驱动程序)
最佳答案
以这种方式它很容易工作..而不是单独指定每个 jar 的版本..
#!/bin/sh
# build all other dependent jars in OTHER_JARS
JARS=`find ../lib -name '*.jar'`
OTHER_JARS=""
for eachjarinlib in $JARS ; do
if [ "$eachjarinlib" != "APPLICATIONJARTOBEADDEDSEPERATELY.JAR" ]; then
OTHER_JARS=$eachjarinlib,$OTHER_JARS
fi
done
echo ---final list of jars are : $OTHER_JARS
echo $CLASSPATH
spark-submit --verbose --class <yourclass>
... OTHER OPTIONS
--jars $OTHER_JARS,APPLICATIONJARTOBEADDEDSEPERATELY.JAR
使用
tr
unix 命令也可以提供帮助,如下例所示。--jars $(echo/dir_of_jars/*.jar | tr ' ' ',')
关于java - Spark spark-submit --jars arguments 想要逗号列表,如何声明一个 jars 目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34738296/