简体   繁体   中英

calling a java program in a python script : Classpath Error

i am running a python script, which is essentially about information retrieval. Since one execution of the script takes a very long time, i want to run parallel scripts. I am calling the java program using the following code in my script:

x='java -cp "lib/*:esalib.jar" clldsystem.esa.ESAAnalyzer %s %s' % (word1, word2)
args=shlex.split(x)
print args
p=subprocess.Popen(args)
p.wait()

It works fine. In order to not mix up the input files and temporary result files, i created a new folder within the folder which contains the script. I'm now trying to run a copy of the script from the new folder. I updated the code to:

x='java -cp "../lib/*:esalib.jar" ../clldsystem.esa.ESAAnalyzer %s %s' % (word1, word2)
args=shlex.split(x)
print args
p=subprocess.Popen(args)
p.wait()

But this gives an error:

Error: Could not find or load main class ...clldsystem.esa.ESAAnalyzer

How could i fix this?

The problem is that you are putting the .. dots in the wrong place.

clldsystem.esa.ESAAnalyzer is the Java class that contains the main() method which is to be executed by java . java tries to find clldsystem.esa.ESAAnalyzer by looking through the classes which it loads from the jars specified in the classpath by -cp .

So try replacing

java -cp "../lib/*:esalib.jar" ../clldsystem.esa.ESAAnalyzer

with the following:

java -cp "../lib/*:../esalib.jar" clldsystem.esa.ESAAnalyzer

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