From 5cdccdc4cfec743b62c0209ba7109516c83d38df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=87=95=E9=B9=8F?= Date: Fri, 16 Jul 2021 17:50:15 +0800 Subject: [PATCH] init --- pom.xml | 29 ++++++++++++++++++++++++++++ src/main/java/JavaRunPythonCode.java | 16 +++++++++++++++ src/main/java/JavaRunPythonFile.java | 15 ++++++++++++++ src/main/java/javaPythonFile.py | 3 +++ 4 files changed, 63 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/JavaRunPythonCode.java create mode 100644 src/main/java/JavaRunPythonFile.java create mode 100644 src/main/java/javaPythonFile.py diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..00cc722 --- /dev/null +++ b/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + + org.example + java4python + 1.0-SNAPSHOT + + + org.python + jython-standalone + 2.7.0 + + + + + spring + https://maven.aliyun.com/repository/public + + true + + + true + + + + \ No newline at end of file diff --git a/src/main/java/JavaRunPythonCode.java b/src/main/java/JavaRunPythonCode.java new file mode 100644 index 0000000..16b09fb --- /dev/null +++ b/src/main/java/JavaRunPythonCode.java @@ -0,0 +1,16 @@ +import org.python.util.PythonInterpreter; + +/** + * @author yanpeng + * @version 1.0 + * @desc TODO + * @company 北京中经网软件有限公司 + * @date 2021/7/16 17:43 + */ +public class JavaRunPythonCode { + public static void main(String[] args) { + PythonInterpreter interpreter = new PythonInterpreter(); + interpreter.exec("a='hello world'; "); + interpreter.exec("print a;"); + } +} diff --git a/src/main/java/JavaRunPythonFile.java b/src/main/java/JavaRunPythonFile.java new file mode 100644 index 0000000..a3e85ff --- /dev/null +++ b/src/main/java/JavaRunPythonFile.java @@ -0,0 +1,15 @@ +import org.python.util.PythonInterpreter; + +/** + * @author yanpeng + * @version 1.0 + * @desc TODO + * @company 北京中经网软件有限公司 + * @date 2021/7/16 17:43 + */ +public class JavaRunPythonFile { + public static void main(String[] args) { + PythonInterpreter interpreter = new PythonInterpreter(); + interpreter.execfile("classpath:/javaPythonFile.py"); + } +} diff --git a/src/main/java/javaPythonFile.py b/src/main/java/javaPythonFile.py new file mode 100644 index 0000000..f833ff5 --- /dev/null +++ b/src/main/java/javaPythonFile.py @@ -0,0 +1,3 @@ +a = 1 +b = 2 +print (a + b) \ No newline at end of file