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