如何添加第三方 Java JAR 文件以在 PySpark 中使用 [英] How to add third-party Java JAR files for use in PySpark
问题描述
我有一些用 Java 编写的第三方数据库客户端库.我想通过
I have some third-party database client libraries in Java. I want to access them through
java_gateway.py
例如:通过 Java 网关使 Python 客户端可以使用客户端类(不是 JDBC 驱动程序!):
E.g.: to make the client class (not a JDBC driver!) available to the Python client via the Java gateway:
java_import(gateway.jvm, "org.mydatabase.MyDBClient")
不清楚在哪里将第三方库添加到 JVM 类路径.我试图添加到文件 compute-classpath.sh,但这似乎不起作用.我得到:
It is not clear where to add the third-party libraries to the JVM classpath. I tried to add to file compute-classpath.sh, but that did not seem to work. I get:
Py4jError:试图调用一个包
Py4jError: Trying to call a package
此外,与 Hive 相比:hive JAR 文件不通过文件 compute-classpath.sh 加载,所以这让我怀疑.似乎还有其他一些机制来设置 JVM 端类路径.
Also, when comparing to Hive: the hive JAR files are not loaded via file compute-classpath.sh, so that makes me suspicious. There seems to be some other mechanism happening to set up the JVM side classpath.
推荐答案
你可以添加外部 jars 作为 pyspark 的参数
You can add external jars as arguments to pyspark
pyspark --jars file1.jar,file2.jar
这篇关于如何添加第三方 Java JAR 文件以在 PySpark 中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!