使用Python和py4j导入Java包com.typesafe.config.impl.SimpleConfig。

huangapple go评论99阅读模式
英文:

Import java package com.typesafe.config.impl.SimpleConfig using python with py4j

问题

from py4j.java_gateway import java_import

java_import(jvm, 'com.typesafe.config.impl.SimpleConfig')
java_import(jvm, 'com.typesafe.config.ConfigFactory')
java_import(jvm, 'com.typesafe.config.Config')

config = jvm.SimpleConfig()
factory = jvm.ConfigFactory
英文:

I can import all from java.* using the jvm from JavaGateway of py4j

for example:

jvm.java.util.ArrayList
jvm.java.lang.System
random = jvm.java.util.Random()
random.nextInt(3)

or in this form:

from py4j.java_gateway import java_import
java_import(jvm,'java.util.*')
random = jvm.Random()
random.nextInt(3)

I need to import:

com.typesafe.config.impl.SimpleConfig
com.typesafe.config.ConfigFactory
com.typesafe.config.Config

But it doesn't work, I tried these ways:

jvm.com.typesafe.config.impl.SimpleConfig
jvm.java.com.typesafe.config.impl.SimpleConfig
jvm.java.typesafe.config.impl.SimpleConfig
java_import(jvm,'com.typesafe.config.*')
java_import(jvm,'com.typesafe.config.impl.*')
jvm.SimpleConfig
jvm.impl.SimpleConfig

all returns: py4j.java_gateway.JavaPackage
not py4j.java_gateway.JavaClass as needed

答案1

得分: 1

我不清楚您想要翻译的具体内容。请提供您需要翻译的英文文本,我会帮您进行翻译。

英文:

I had to download the JAR
https://repo1.maven.org/maven2/com/typesafe/config/1.4.1/config-1.4.1.jar
then add the JAR in the ("spark.jars", jar_path)

huangapple
  • 本文由 发表于 2020年7月30日 13:04:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63166519.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定