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

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

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

问题

  1. from py4j.java_gateway import java_import
  2. java_import(jvm, 'com.typesafe.config.impl.SimpleConfig')
  3. java_import(jvm, 'com.typesafe.config.ConfigFactory')
  4. java_import(jvm, 'com.typesafe.config.Config')
  5. config = jvm.SimpleConfig()
  6. factory = jvm.ConfigFactory
英文:

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

for example:

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

or in this form:

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

I need to import:

  1. com.typesafe.config.impl.SimpleConfig
  2. com.typesafe.config.ConfigFactory
  3. com.typesafe.config.Config

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

  1. jvm.com.typesafe.config.impl.SimpleConfig
  2. jvm.java.com.typesafe.config.impl.SimpleConfig
  3. jvm.java.typesafe.config.impl.SimpleConfig
  4. java_import(jvm,'com.typesafe.config.*')
  5. java_import(jvm,'com.typesafe.config.impl.*')
  6. jvm.SimpleConfig
  7. 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:

确定