Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.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
Python调用Java导致错误:无法找到或加载主类_Java_Python_Django_Subprocess - Fatal编程技术网

Python调用Java导致错误:无法找到或加载主类

Python调用Java导致错误:无法找到或加载主类,java,python,django,subprocess,Java,Python,Django,Subprocess,我在MAC OS的localserver中使用Django项目中的java程序时遇到问题 我在Django项目中安装了ResumeParser,如: --Django项目 --附件1 --附件2 --简历助理 这是我的代码,但上面写着“无法找到或加载主类” 有什么线索可以解决这个问题吗?我在StackOverflow中尝试了所有与此主题相关的帖子,但没有成功 提前感谢您将分隔符参数与以空格分组的参数混为一谈 cmd = ['java', '-cp', 'bin/:../GATEFiles/lib

我在MAC OS的localserver中使用Django项目中的java程序时遇到问题

我在Django项目中安装了ResumeParser,如:

--Django项目 --附件1 --附件2 --简历助理

这是我的代码,但上面写着“无法找到或加载主类”

有什么线索可以解决这个问题吗?我在StackOverflow中尝试了所有与此主题相关的帖子,但没有成功


提前感谢

您将分隔符参数与以空格分组的参数混为一谈

cmd = ['java', '-cp', 'bin/:../GATEFiles/lib/:../GATEFiles/bin/gate.jar:lib/*', 'code4goal.antony.resumeparser.ResumeParserProgram %s textOutput.json' % resume]
最后一个参数被视为单个参数,并受
子流程
的空格保护:

“code4goal.antony.resumeparser.ResumeParserProgram resume\u value textOutput.json”

=>整个
“classparam1param2”
被视为您的类:难怪找不到它

拆分所有参数,它将工作,
子流程
不会对参数进行分组,不引用(注意将
恢复
对象强制转换为
str
):


两周后,我开始工作了。 必须将所有文件复制到ResumeParser/ResumeTransformer目录

此外,还需要通知当前目录进行文件解析

以下是实施方案:

# first save the file
if form.is_valid():
    f = form.save(commit=False)

    resume = form.cleaned_data['resume']
    f.resume = resume
    f.save()

    # copy file to the CV parser dir so java can parse the file
    cf = "." + f.resume.url
    shutil.copy2(cf, 'ResumeParser/ResumeTransducer')

    # get file to convert
    fl_name = str(f.resume).split('/')[-1]

    # get file name to make json output
    base_name = os.path.splitext(fl_name)[0]

    cmd = "java -cp 'bin/*:../GATEFiles/lib/*:../GATEFiles/bin/gate.jar:lib/*' code4goal.antony.resumeparser.ResumeParserProgram %s %s.json" % (fl_name, base_name)

    # get the current working dir       
    os.chdir("ResumeParser/ResumeTransducer")

    # call java
    subprocess.Popen(cmd, shell=True)

谢谢让·弗朗索瓦·法布

谢谢你的快速回答。现在我有一个新错误:execv()arg 2必须只包含stringssorry!需要将
resume
对象转换为字符串,请参见我的编辑。
cmd = ['java', '-cp', 'bin/:../GATEFiles/lib/:../GATEFiles/bin/gate.jar:lib/*', 'code4goal.antony.resumeparser.ResumeParserProgram', str(resume),'textOutput.json']
# first save the file
if form.is_valid():
    f = form.save(commit=False)

    resume = form.cleaned_data['resume']
    f.resume = resume
    f.save()

    # copy file to the CV parser dir so java can parse the file
    cf = "." + f.resume.url
    shutil.copy2(cf, 'ResumeParser/ResumeTransducer')

    # get file to convert
    fl_name = str(f.resume).split('/')[-1]

    # get file name to make json output
    base_name = os.path.splitext(fl_name)[0]

    cmd = "java -cp 'bin/*:../GATEFiles/lib/*:../GATEFiles/bin/gate.jar:lib/*' code4goal.antony.resumeparser.ResumeParserProgram %s %s.json" % (fl_name, base_name)

    # get the current working dir       
    os.chdir("ResumeParser/ResumeTransducer")

    # call java
    subprocess.Popen(cmd, shell=True)