python调用java代码
2019-06-27 本文已影响0人
huxt
1.python
JPype下载链接:https://www.lfd.uci.edu/~gohlke/pythonlibs/#jpype
pip install JPype1-0.6.3-cp36-cp36m-win_amd64.whl
https://blog.csdn.net/ll666634/article/details/79232127
2.java项目打包
python3.python程序调用
# -*-coding:utf-8-*-
import jpype
from jpypeimport *
# 获得默认jvm路径,即jvm.dll文件路径
jvmPath = jpype.getDefaultJVMPath()
print(jvmPath)
# java扩展包路径
ext_classpath =r'F:\Jpython\target\Jpython-1.0-SNAPSHOT.jar'
jvmArg ='-Djava.class.path=%s' % ext_classpath
print(jvmArg)
if not jpype.isJVMStarted():
# 启动Java虚拟机
jpype.startJVM(jvmPath, '-ea', jvmArg)
jpype.java.lang.System.out.println('Hello world!')
# 获取相应的Java类
javaClass = JClass("com.Javatest")
jd = javaClass()
jprint = java.lang.System.out.println
jprint(jd.run("waw"))
a = jd.testParam("test")
print(a)
shutdownJVM()
执行结果如下