Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JPype total newbie查询从Python调用jar文件_Python_Jar_Jpype - Fatal编程技术网

使用JPype total newbie查询从Python调用jar文件

使用JPype total newbie查询从Python调用jar文件,python,jar,jpype,Python,Jar,Jpype,因此,我一直在使用subprocess.call从Python运行jar文件,如下所示: subprocess.call(['java','-jar','jarFile.jar',-a','input_file','output_file']) 将结果写入外部输出文件。和-a是一个选项 现在我想用python分析输出文件,但不想再次打开该文件。因此,我想将jarFile.jar作为Python函数运行,如: output=jarFile(input_file) 我已经安装了JPype并使其正

因此,我一直在使用subprocess.call从Python运行jar文件,如下所示:

subprocess.call(['java','-jar','jarFile.jar',-a','input_file','output_file'])
将结果写入外部输出文件。和-a是一个选项

现在我想用python分析输出文件,但不想再次打开该文件。因此,我想将jarFile.jar作为Python函数运行,如:

output=jarFile(input_file)
我已经安装了JPype并使其正常工作,我已经设置了类路径并启动了JVM环境:

import jpype

classpath="/home/me/folder/jarFile.jar"

jpype.startJVM(jpype.getDefaultJVMPath(),"-Djava.class.path=%s"%classpath)
现在我被卡住了…

java-jar jarFile.jar执行在jar中配置的类文件的主方法。 如果您提取jar文件的META-INF/MANIFEST.MF,并使用任何zip工具打开jar,就会找到该类名。寻找Main类的值。例如,如果是com.foo.bar.Application,您应该能够像这样调用main方法

def jarFile(input_file):
    # jpype is started as you already did
    assert jpype.isJVMStarted()
    tf = tempfile.NamedTemporaryFile()
    jpype.com.foo.bar.Application.main(['-a', input_file, tf.name])
    return tf
我不确定tempfile模块的正确用法,请检查您自己