如何从linuxshell启动py4jgatewayserver?

2024-06-13 01:05:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在我的Linux主机上运行py4j。在

我的爪哇肌肉很弱,但我知道Python。在

我从安装Anaconda5.0.1开始,它为我提供了Python3.6.3

接下来,我使用shell命令安装py4j包:

conda install py4j

然后我安装了Java sdk放在这里:

^{pr2}$

我设置环境变量:

^{3}$

我使用这个shell命令来查看它:

java -version

上面写着:

java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

接下来我研究了这一页:

https://www.py4j.org/index.html

它要求我启动一个依赖于此Java文件的服务器:

public class AdditionApplication {

  public int addition(int first, int second) {
    return first + second;
  }

  public static void main(String[] args) {
    AdditionApplication app = new AdditionApplication();
    // app is now the gateway.entry_point
    GatewayServer server = new GatewayServer(app);
    server.start();
  }
}

问:在Linux上,应该运行哪些shell命令来启动上面Java文件中列出的服务器?在


Tags: 文件命令buildappversionlinuxjavapublic
1条回答
网友
1楼 · 发布于 2024-06-13 01:05:16

我用google学习了一些shell命令javac和java。 然后我写了一个很好用的shell脚本:

#!/bin/bash

# ~/cryp/java_python/AdditionApplication.bash
# This script should start a py4j server.
# Ref:
# https://www.py4j.org/index.html

cd ~/cryp/java_python/

export JAVA_HOME=${HOME}/jdk
export PATH="${JAVA_HOME}/bin:${PATH}"

javac -cp py4j0.10.6.jar   py4j/examples/AdditionApplication.java
java  -cp py4j0.10.6.jar:. py4j.examples.AdditionApplication

exit

相关问题 更多 >