我从https://github.com/Netflix/photon构建了Netflix Photon docker镜像,其工作方式与我能够启动容器并运行提供的java应用程序一样。
在此之上,我安装了Python3,gcc和JPype1-py3,但无法加载Photon Java类。
我可以使用以下命令成功启动JVM
startJVM(getDefaultJVMPath(),“-ea”,“-Djava.class.path = / source / build / libs”) java.lang.System.out.println(“ hello world”) 你好世界
所以我知道JVM本身正在工作,但是每当我尝试从Photon加载类时,都会出现错误:
>>> s = JClass("com.netflix.imflibrary.st2067_2.ImpAsset")
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/jpype/_jclass.py", line 55, in JClass
raise _RUNTIMEEXCEPTION.PYEXEC("Class %s not found" % name)
jpype._jexception.ExceptionPyRaisable: java.lang.Exception: Class com.netf;ox/imflibrary.st2067_2.IMPAsset not found
有人能够使用JPype直接与Netflix光子类集成吗?我宁愿不限于通过子流程运行提供的应用程序。
答案 0 :(得分:0)
板球!?
好吧,我还是想通了,必须像这样加载jar文件:
try:
from jpype import *
classpath="/source/build/libs/Photon-0.1.0-SNAPSHOT.jar:/source/build/libs/log4j-1.2.17.jar:/source/build/libs/regxmllib-1.1.1.jar:/source/build/libs/slf4j-log4j12-1.7.25.jar:/source/build/libs/jsr305-3.0.1.jar:/source/build/libs/log4j.properties:/source/build/libs/slf4j-api-1.7.25.jar"
startJVM(getDefaultJVMPath(), "-Djava.class.path=%s" % classpath)
print("JVM started: ",getDefaultJVMPath())
print("classpath=",classpath)
except Exception as e:
print("error launching JVM:", traceback.format_exc())
exit()
print("Starting scan of",scanfolder)
IMPAnalyzer = JClass("com.netflix.imflibrary.app.IMPAnalyzer")
IMPFile = java.io.File(scanfolder)
error_fatal = 0
error_nonfatal = 0
error_warning = 0
if IMPFile.isDirectory():
result_dict = {}
IMPresult_iterator = IMPAnalyzer.analyzePackage(IMPFile).entrySet().iterator()
while IMPresult_iterator.hasNext():
resultpair = IMPresult_iterator.next()
# print(resultpair.getKey(),":")
if len(resultpair.getValue()) > 0:
error_list = []
list_iterator = resultpair.getValue().iterator()
while list_iterator.hasNext():
errorobject = list_iterator.next()
error_list.append(str(errorobject.errorLevel) + ":" + str(errorobject.errorCode) + ":" + errorobject.toString())
if str(errorobject.errorLevel) == "WARNING":
error_warning += 1
elif str(errorobject.errorLevel) == "NON FATAL":
error_nonfatal += 1
elif str(errorobject.errorLevel) == "FATAL":
error_fatal += 1
result_dict[resultpair.getKey()] = error_list
else:
result_dict[resultpair.getKey()]='Ok'
print(scanfolder,"scanned with",error_fatal,"fatal error(s),",error_nonfatal,"nonfatal error(s), and",error_warning,"warning(s)")
pprint.pprint(result_dict)
else:
print(scanfolder,"does not appear to be a valid folder")