SoFunction
Updated on 2024-11-12

Python using jpype import multiple Jar exception problem and solution

Exception for importing multiple Jars using jpype

When using Jpype to import multiple Jar packages, the following code throws an exception when executed on a linux system.

jar_path1 = './lib/'
jar_path2 = './lib/'
jar_path = "-=%s;%s"%(jar_path1,jar_path2)

TypeError: Class is not found

This exception stems from a problem with the linux system and windows system spacers.

The following loading method was used to solve the problem successfully

('-ea', classpath=['path1', 'path2'])
print((''))

Python calls to jpype report errors.

OSError JVM is already startedcap (a poem)JVM cannot be restarted

Solution: Since the error is reported because the virtual machine has been turned on when turned on again will report an error, so we turn on if the error reported that the virtual machine has been turned on directly skip the

    try:
        jvmPath = ()
        (jvmPath, "-ea", "-=%s" % './jars/jpype_test_new.jar')
    except Exception as e:
        print(str(e))

summarize

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.