最小的工作示例:
//AdditionApplication.java
import py4j.GatewayServer;
public class AdditionApplication {
public static void main(String[] args) {
AdditionApplication app = new AdditionApplication();
// app is now the gateway.entry_point
GatewayServer server = new GatewayServer(app);
server.start();
}
}
编译(确保-cp
py4j 的路径有效,否则调整它使其指向正确的位置):
javac -cp /usr/local/share/py4j/py4j0.9.jar AdditionApplication.java
运行:
java -cp .:/usr/local/share/py4j/py4j0.9.jar AdditionApplication
现在,如果您运行 python 脚本,在运行 java AdditionApplication 的终端中,您应该会看到如下内容:
>>> Hello World!