4
我在Python中使用JPype,所以我可以調用Java函數。我無法導入我自己的jar文件。如何使用JPype在Python中導入用戶構建的jar?
我有這個jar:/home/di/eclipse_plugins/plugins/org.eclipse.birt.report.engine_4.2.1.v20120820.jar
在org.eclipse.birt.report.engine.api
包有一個EngineConfig
類定義。我正試圖實例化並使用我在該jar中的這個類。在常規的Java,這是我必須:
import org.eclipse.birt.report.engine.api.EngineConfig;
EngineConfig config = new EngineConfig();
config.setLogConfig("/home/di/logs");
我有這個在Python:
import jpype
from jpype import *
jvmPath = jpype.getDefaultJVMPath()
jpype.startJVM(jvmPath, "-Djava.class.path=/home/di/eclipse_plugins/plugins/*.jar")
engineConfig = JPackage("org").eclipse.birt.report.engine.api.EngineConfig
engineConfig.setLogConfig("/home/di/logs")
jpype.shutdownJVM()
然而,當我運行它,我得到這個錯誤:
Traceback (most recent call last):
File "test.py", line 15, in <module>
engineConfig.setLogConfig()
File "/usr/lib64/python2.6/site-packages/jpype/_jpackage.py", line 53, in __call__
raise TypeError, "Package "+self.__name+" is not Callable"
TypeError: Package org.eclipse.birt.report.engine.api.EngineConfig.setLogConfig is not Callable
弄來的解決方案上面,或者你可以請分享Python中調用Java方法的工作示例,我也面臨類似的問題。 – Sankalp 2017-01-22 19:15:50