Skip to content

How to write Python 3 code in a Java web code?

I am trying to write inside a JSP/Servlet Java web project, a python-3 Machine Learning code depends on torch and some advanced frameworks.

I tried:

  1. to use Jython but it did not work because it only works for python 2 programs.
  2. to use ProcessBuilder and Runtime.getRuntime().exec(“”) to execute the python file but nothing worked.

Is there any suggestions on how to write that Python code in the Java project or communicate them?


For option #2, you’d need to pass the python executable into the exec method. For example: