要有jvmPath
可以 jpype.getDefaultJVMPath()获得
然后jpype.startJVM(jvmPath)打开jvm
javaClass = jpype.JClass('com.xx.xx')
javaInstance = javaClass(value) //构造函数
javaInstance.xxxx( “ xxxxx ” )//方法调用
调用完毕后jpype.shutdownJVM()
底层实现跟jni有关系。
import jpypefrom jpype import JavaException
jvmPath = jpype.getDefaultJVMPath() #the path of jvm.dll
classpath = "F:\\test\\cipher" #the path of PasswordCipher.class
jvmArg = "-Djava.class.path=" + classpath
if not jpype.isJVMStarted(): #test whether the JVM is started
jpype.startJVM(jvmPath,jvmArg) #start JVM
javaClass = jpype.JClass("PasswordCipher") #create the Java class
try:
testString = "congratulations"
print "original string is : ", testString
#call the run function of Java class
encryptedString = javaClass.run("encrypt", testString)
print "encrypted string is : ", encryptedString
#call the run function of Java class
decryptedString = javaClass.run("decrypt", encryptedString)
print "decryped string is : ", decryptedString
except JavaException, ex:
print "Caught exception : ", JavaException.message()
print JavaException.stackTrace()
except:
print "Unknown Error"
finally:
jpype.shutdownJVM() #shut down JVM
------------------
----------------------------pppppppppppppppppppppppython--------------------
另外At the moment, it is not possible to use threads created from Java, since there is no callback available
Non-static inner classes cannot be instantiated from Python code. Instances received from Java code thay can be used without problem
Write it all in Python, then write only those parts that need it in C(java)
再copy就copy个没完了,直接传送门:http://jpype.sourceforge.net/doc/user-guide/userguide.html