Browse Source

init

master
燕鹏 3 years ago
commit
5cdccdc4cf
  1. 29
      pom.xml
  2. 16
      src/main/java/JavaRunPythonCode.java
  3. 15
      src/main/java/JavaRunPythonFile.java
  4. 3
      src/main/java/javaPythonFile.py

29
pom.xml

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>java4python</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>spring</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>

16
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;");
}
}

15
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");
}
}

3
src/main/java/javaPythonFile.py

@ -0,0 +1,3 @@
a = 1
b = 2
print (a + b)
Loading…
Cancel
Save