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:
- to use Jython but it did not work because it only works for python 2 programs.
- to use ProcessBuilder and Runtime.getRuntime().exec(“pythonFile.py”) 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?
Advertisement
Answer
For option #2, you’d need to pass the python executable into the exec method. For example:
Runtime.getRuntime().exec("python pythonFile.py")
Source: https://www.edureka.co/community/358/how-to-execute-a-python-file-with-few-arguments-in-java