[英]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.