python调用jar包类

Posted on 2016-07-04 12:41  NooBkey  阅读(4399)  评论(0编辑  收藏  举报

#!/usr/bin/python2.7
#coding:utf8
import sys
import jpype
import os.path


phone_num = sys.argv[1]
#jarpath = os.path.join(os.path.abspath('.'), 'build/jar')
jarpath = '/home/script/p_code/build/jar'
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath)
Test = jpype.JClass('com.stephen.util.resourcedict.area.COUNTRY') # 取得包org.wg3i.test中的类Test
#t = Test() # 创建Test实例
a=Test.getByCode(phone_num,False) # 尝试调用类的一个方法
#t.setString("Hello, World") #给定String
#s = t.getString() # 获取String
#print '号码:37064720063'
#print type(a)
b = a.toString().split(',')[4]
print b.encode('utf8')
#b = a.toArray()
jpype.shutdownJVM()

Copyright © 2024 NooBkey
Powered by .NET 9.0 on Kubernetes