pip install jpype1
from jpype import *
'''
调用标准代码
'''
if __name__ == "__main__":
startJVM(getDefaultJVMPath(), "-ea")
java.lang.System.out.println("hello python java")
shutdownJVM()
public class JPypeDemo{
public String say(String user){
return "java say: " + user;
}
public int calc(int a, int b){
return a + b;
}}
javac JPypeDemo.java
jar cvf JPypeDemo.jar JPypeDemo.class
from jpype import *
import os
if __name__ == "__main__":
startJVM(getDefaultJVMPath(), "-ea",
"-Djava.class.path=%s" % (os.getcwd() + "/JPypeDemo.jar"))
JDClass = JClass("JPypeDemo")
jd = JDClass()
jprint = java.lang.System.out.println
jprint(jd.say("deeptest"))
jprint(jd.calc(1, 4))
shutdownJVM()