[英]Error: Could not find or load main class in python
I am trying to run this command in Python: 我正在尝试在Python中运行以下命令:
java JSHOP2.InternalDomain logistics
It works well when I run it in cmd. 当我在cmd中运行它时效果很好。
I wrote this in Python: 我用Python写的:
args = ['java',
r"-classpath",
r".;./JSHOP2.jar;./antlr.jar",
r"JSHOP2.InternalDomain",
thisDir+"/logistics"
]
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
proc.communicate()
I have the jar files in the current directory. 我在当前目录中有jar文件。
but I got this error: Error: Could not find or load main class JSHOP2.InternalDomain 但是我收到此错误:错误:无法找到或加载主类JSHOP2.InternalDomain
Does anyone know what the problem is? 有人知道问题出在哪里吗? can't it find the jar files?
找不到jar文件?
You can't count on the current working directory always being the same when running your Python code. 运行Python代码时,您不能指望当前的工作目录总是相同的。 Explicitly set a working directory using the
cwd
argument: 使用
cwd
参数明确设置工作目录:
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
cwd='/directory/containing/jarfiles')
Alternatively, use absolute paths in your -classpath
commandline argument. 或者,在
-classpath
命令行参数中使用绝对路径。 If that path is thisDir
, then use that: 如果该路径是
thisDir
,则使用该路径:
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
cwd=thisDir)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.