尝试使用jpype从python调用java类时获取类未找到异常。以下是版本和路径详细信息:
JPype版本:JPype1-py3
Python:3.6
Java:1.8.0_171
Java文件路径:/home/neha/Downloads/fontAttributes/PDFFontExtractor.java
Python文件路径:/home/neha/Downloads/call_java.py
以下是Python代码:call_java.py
import jpype
from jpype import *
cpath="-Djava.class.path=%s" % ("/home/neha/Downloads")
startJVM(getDefaultJVMPath(), "-ea",cpath)
Test = JClass('fontAttributes.PDFFontExtractor')
Test.getFontAttributes()
java.lang.System.out.println(str)
shutdownJVM()
输出:
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server/libjvm.so
Traceback (most recent call last):
File "call_java.py", line 14, in <module>
Test = JClass('fontAttributes.PDFFontExtractor')
File "/usr/local/lib/python3.6/dist-packages/jpype/_jclass.py", line 55, in JClass
raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name)
jpype._jexception.ExceptionPyRaisable: java.lang.Exception: Class fontAttributes.PDFFontExtractor not found