使用JPype實現Python調用JAVA程序


 1 '''
 2 Created on 2016年6月1日
 3 
 4 @author: cero
 5 '''
 6 import jpype
 7 
 8 jvmPath = jpype.getDefaultJVMPath()
 9 ext_classpath = '/home/cero/temp/chinapnr.jar'
10 jvmArg = '-Djava.class.path=' + ext_classpath
11 if not jpype.isJVMStarted():
12     jpype.startJVM(jvmPath, jvmArg)
13     system = jpype.java.lang.System
14     system.out.println('hello world!')
15     system.out.println(system.getProperty("user.dir"))
16     SecureLink = jpype.JClass('chinapnr.SecureLink')
17     sl = SecureLink()
18     ret = sl.EncMsg("/home/cero/temp/PgPubk.key", 'aaaa')
19     EncMsg = sl.getEncMsg()
20     print(ret)
21     print(EncMsg)
22     jpype.shutdownJVM()

開始一直無法導入第三方包,提示class not found;

使用jar包的完整路徑后成功導入。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM