jpype安装
1、opensdk 安装的时候会报错
jpype command '/usr/bin/gcc' failed with exit status 1
a、需要安装oracle版本的,我这里安装的是jdk-7u25-linux-x64.rpm
b、设置环境变量 export JAVA_HOME=/usr/java/jdk1.7.0_25/
c、source /etc/profile
2、查看rpm包的安装目录
rpm -ql jdk
3、例子
def test(arg1,arg2,arg3):
import os
import jpype
jvm_path = jpype.getDefaultJVMPath()
class_path = os.path.join(settings.MEDIA_ROOT,"java_class")
jvm_arg = "-Djava.class.path=%s" %class_path
if not jpype.isJVMStarted():
jpype.startJVM(jvm_path, jvm_arg)
if not jpype.isThreadAttachedToJVM(): #特别重要
jpype.attachThreadToJVM() #特别重要
ret = jpype.JPackage("test").TestKlass.get_v(
arg1,arg2,arg3
)
return ret