简体   繁体   中英

Error: Could not find or load main class in python

I am trying to run this command in Python:

java JSHOP2.InternalDomain logistics

It works well when I run it in cmd.

I wrote this in 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.

but I got this error: Error: Could not find or load main class JSHOP2.InternalDomain

Does anyone know what the problem is? can't it find the jar files?

You can't count on the current working directory always being the same when running your Python code. Explicitly set a working directory using the cwd argument:

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

Alternatively, use absolute paths in your -classpath commandline argument. If that path is thisDir , then use that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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