0

I want to run py4j on my Linux host.

My Java muscles are weak but I do know Python.

I started by installing Anaconda 5.0.1 which gives me Python 3.6.3

Next I installed the py4j package with a shell command:

conda install py4j

Then I installed Java sdk and put it here:

$HOME/jdk/

And I set env variables:

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

I use this shell command to see it:

java -version

It says:

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)

Next I studied this page:

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

It asks me to start a server which relies on this Java file:

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();
  }
}

Question: On Linux, which shell commands should I run to start the server listed in the above Java file?

user3676943
  • 913
  • 1
  • 13
  • 27

1 Answers1

0

I used google to learn a little about shell commands javac and java. Then I wrote a shell script which works well:

#!/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
user3676943
  • 913
  • 1
  • 13
  • 27