我无法为我的 python 代码加载 .jar 文件,这是我的 default.py 代码
from quickstart import HelloWorld
import jpype
import os.path
path =os.path.join("/home/nhp06/Documents/Aspose_Cells_java_for_Python/src/lib/aspose-cells-8.6.3.jar")
dataDir = os.path.join(os.path.abspath("./"), "tests/")
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % path)
hw = HelloWorld(dataDir)
hw.main()
shutdownJVM()
这是我的init .py代码
import jpype
class HelloWorld:
def __init__(self,dataDir):
self.dataDir = dataDir
self.Workbook = jpype.JClass("com.aspose.cells.Workbook")
self.FileFormatType = jpype.JClass("com.aspose.cells.FileFormatType")
def main(self):
workbook = self.Workbook()
sheet = workbook.getWorksheets().get(0)
cell = sheet.getCells().get("A1")
cell.setValue("Hello World!")
file_format_type = self.FileFormatType
workbook.save(self.dataDir + "HelloWorld.xls" , file_format_type.EXCEL_97_TO_2003 )
print "Document has been saved, please check the output file.";
当我尝试运行上面的代码时,我得到了错误
“引发_RUNTIMEEXCEPTION.PYEXC(“找不到类%s”%名称)jpype._jexception.ExceptionPyRaisable:java.lang.Exception:找不到类com.aspose.cells.Workbook”
我无法弄清楚为什么会发生此错误。我仔细检查了 .jar 文件的路径。