Practical use of Java class/JAR in Python?

僤鯓⒐⒋嵵緔 提交于 2019-12-02 01:37:34

To save time to many people, I post the module I used for JPype, this is working nicel to load JAR.

import jpype as jp; import numpy as np; import os as os
jarpath= r"D:\zjavajar\\"
mavenurl= r"http://mvnrepository.com/artifact/"



# StartJVM (add "-Xmx" option with 1024M if crash due to not enough memory )
def importJAR(path1="", path2="", path3="", path4=""):
   classpath = path1
   if path2 != "":  classpath = os.pathsep.join((classpath, path2))   
   if path3 != "":  classpath = os.pathsep.join((classpath, path3))
   if path4 != "":  classpath = os.pathsep.join((classpath, path4))        
   jp.startJVM(jp.getJVMPath(),"-ea", "-Djava.class.path=%s" % classpath)


def showLoadedClass(): #Code to see the JAR loaded.
   classloader = jp.java.lang.ClassLoader.getSystemClassLoader(); vv= []; 
   for x in classloader.getURLs():  vv.append(x.toString());         
   return vv


def loadSingleton(class1):  single= jp.JClass(class1);  return Single.getInstance()


def java_print(x):  jp.java.lang.System.out.println(x)   #Print in Java Console
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!