Calling Python in Java?

前端 未结 11 1372
北荒
北荒 2020-11-22 13:04

I am wondering if it is possible to call python functions from java code using jython, or is it only for calling java code from python?

11条回答
  •  萌比男神i
    2020-11-22 13:43

    It's not smart to have python code inside java. Wrap your python code with flask or other web framework to make it as a microservice. Make your java program able to call this microservice (e.g. via REST).

    Beleive me, this is much simple and will save you tons of issues. And the codes are loosely coupled so they are scalable.

    Updated on Mar 24th 2020: According to @stx's comment, the above approach is not suitable for massive data transfer between client and server. Here is another approach I recommended: Connecting Python and Java with Rust(C/C++ also ok). https://medium.com/@shmulikamar/https-medium-com-shmulikamar-connecting-python-and-java-with-rust-11c256a1dfb0

提交回复
热议问题