我使用py4j从python代码调用Java方法。当我在eclipse上启动java网关并使用python代码调用java方法时,我得到了正确的响应。但是,当我在tomcat上部署与war文件相同的java程序,然后使用python代码调用部署在tomcat上的java方法时,我得到了以下错误。在
Java代码:
package testjav;
import py4j.GatewayServer;
public class Helloworld {
public String sayhello() {
System.out.println("Hi there");
return "hi";
}
public static void main(String[] args) {
GatewayServer gatewayServer = new GatewayServer(new Helloworld());
gatewayServer.start();
System.out.println("Gateway Server Started");
}
}
Python代码:
^{pr2}$Tomcat错误:
Python错误:
Traceback (most recent call last):
File "C:\Users\******\Documents\*****\helloworld\tasksHello\tasks.py", line 24, in <module>
out = gateway.entry_point.sayhello()
File "C:\Users\******\AppData\Local\Continuum\anaconda3\lib\site-packages\py4j\java_gateway.py", line 1160, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "C:\Users\*******\AppData\Local\Continuum\anaconda3\lib\site-packages\py4j\protocol.py", line 318, in get_return_value
value = OUTPUT_CONVERTER[type](answer[2:], gateway_client)
KeyError: 'T'
我通过查看py4j模块代码检查了这个answer变量。 对于jvm运行,它返回:yshi,因为hi是输出,ys由py4j使用。我不明白为什么会这样。请引导我。在
目前没有回答
相关问题 更多 >
编程相关推荐