繁体   English   中英

错误:无法在python中找到或加载主类

[英]Error: Could not find or load main class in python

我正在尝试在Python中运行以下命令:

java JSHOP2.InternalDomain logistics

当我在cmd中运行它时效果很好。

我用Python写的:

args = ['java', 
        r"-classpath", 
        r".;./JSHOP2.jar;./antlr.jar", 
        r"JSHOP2.InternalDomain", 
        thisDir+"/logistics" 
       ] 
    proc = subprocess.Popen(args, stdout=subprocess.PIPE) 
    proc.communicate() 

我在当前目录中有jar文件。

但是我收到此错误:错误:无法找到或加载主类JSHOP2.InternalDomain

有人知道问题出在哪里吗? 找不到jar文件?

运行Python代码时,您不能指望当前的工作目录总是相同的。 使用cwd参数明确设置工作目录:

proc = subprocess.Popen(args, stdout=subprocess.PIPE, 
                        cwd='/directory/containing/jarfiles')

或者,在-classpath命令行参数中使用绝对路径。 如果该路径是thisDir ,则使用该路径:

proc = subprocess.Popen(args, stdout=subprocess.PIPE, 
                        cwd=thisDir)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM