javapythonjvmjpype

<JAVA_HOME>/lib/ext exists, extension mechanism no longer supported


What is the correct way to add jars to the JVM classpath in python via jpype?

I initially used Jpype.startJVM(jvmPath, "-Djava.class.path=%s" % (paths)).

But I understand that extension mechanism is depreciated and the error log suggests I use "-classpath"

I tried the below (and used several variations) but I get an unrecognized option error Jpype.startJVM(jvmPath, "-classpath =%s" % (paths)).

I also tried Jpype.startJVM(jvmPath, classpath = paths) but I get the extension mechanism is depreciated error


Solution

  • Specifying a class path using -Djava.class.path=… instead of -classpath … is unusual, but not related to the removed extension mechanism at all. As the error message says, the problem is the existence of <JAVA_HOME>/lib/ext.

    To demonstrate the issue (using Windows in this example)

    E:\java>jdk-11.0.1\bin\java -version
    openjdk version "11.0.1" 2018-10-16
    OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
    OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode, sharing)
    
    E:\java>mkdir jdk-11.0.1\lib\ext
    
    E:\java>jdk-11.0.1\bin\java -version
    <JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; Use -classpath instead.
    .Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    
    E:\java>rmdir jdk-11.0.1\lib\ext
    
    E:\java>jdk-11.0.1\bin\java -version
    openjdk version "11.0.1" 2018-10-16
    OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
    OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode, sharing)
    

    The pure Java installation has no ext folder, so an installation program must have created it, assuming the old extension mechanism that doesn’t exist anymore. Since running software under this wrong assumption can cause even more, hard to diagnose problems, the Java vendor decided to bail out immediately when this folder exist, unconditionally.

    So you have to remove that folder. If it is not empty, it likely contains jar files you need for your application. So you have to move them to a new location where you can maintain them. Then, you have to include them in your class path. Whether you use -Djava.class.path=… or -classpath … is not relevant.

    To address the issue with the command line option syntax, it’s -classpath path, without any = sign. Depending on the API used to launch a new process, you have to ensure that it is treated as two arguments, -classpath, followed by the actual path, if you don’t provide a single command line string that is broken into arguments by the shell.