我无法为我的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文件的路径。