Java通过JYTHON调用python
2017-12-12 10:28
399 查看
Java调用python代码,目前只支持到python2.7
maven pom.xml
maven pom.xml
<!-- https://mvnrepository.com/artifact/org.python/jython --> <dependency> <groupId>org.python</groupId> <artifactId>jython</artifactId> <version>2.7.1b3</version> </dependency>Java代码:
import java.util.Properties; import org.python.util.PythonInterpreter; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub // Python环境初始化 Properties props = new Properties(); props.put("python.console.encoding", "UTF-8"); props.put("python.security.respectJavaAccessibility", "false"); props.put("python.import.site", "false"); Properties preprops = System.getProperties(); PythonInterpreter.initialize(props, preprops, new String[] {}); // 实例化环境和代码执行 PythonInterpreter interpreter = new PythonInterpreter(); interpreter.exec("days=('mod','hello world!!!','Wed','Thu','Fri','Sat','Sun');"); interpreter.exec("print days[1]"); } }
相关文章推荐
- Learning Python -- Java 通过JyThon调用Python实现的规则
- java通过thrift调用python远程执行shell
- java调用python方法的库jython介绍及使用实例
- JAVA调用jython执行python文件
- python调用java jython
- Java调用Python开发环境配置(Eclipse+Jython+PyDev)
- Jython:java调用python文件之第三方包路径问题
- Python与Java之间的相互调用——Jython
- Java调用python的方法(jython)
- idea中通过java程序直接调用python文件
- Java实现调用jython执行python文件的方法
- Python_Java调用Jython
- netty学习九:(window7上)python客户端通过thrift调用java服务端
- Java调用python——Jython
- 通过用第三方包jpype在Python中调用Java代码
- Python 通过Jpype调用Java类
- [java]Java调用python工具类(非jython)
- Jython:java调用python文件之第三方包路径问题
- Jython_Java 调用python
- Python与Java之间的相互调用——Jython