<dependency><groupId>org.python</groupId><artifactId>jython-standalone</artifactId><version>2.7.0</version></dependency>
publicclassApp{publicstaticvoidmain(String[] args ){System.out.println("Hello World!");PythonInterpreter interpreter =newPythonInterpreter(); interpreter.exec("a=[5,4,3,2,1]"); interpreter.exec("print sorted(a)");}}
def add(a,b):return a+b if __name__ =='__main__':print add(1,2)
packagecom.firewolf;importorg.python.core.PyFunction;importorg.python.core.PyInteger;importorg.python.core.PyObject;importorg.python.util.PythonInterpreter;/** * Hello world! * */publicclassApp{publicstaticvoidmain(String[] args ){System.out.println("Hello World!");PythonInterpreter interpreter =newPythonInterpreter(); interpreter.exec("a=[5,4,3,2,1]"); interpreter.exec("print sorted(a)"); interpreter.execfile("src/resources/AddTwoNum.py");PyFunction function = interpreter.get("add",PyFunction.class);// If there is main Method receipt letter main Method .int a =1,b=2;System.out.println(" call py");PyObject pyObject = function.__call__(newPyInteger(a),newPyInteger(2));System.out.println("add The answer is "+pyObject);}}