Modelio
Modelio copied to clipboard
Idiomatic JAR file load for Jython does no longer work in 5.3
Dear all,
in older versions of Modelio (e.g. 4.1) it was possible in a script to load necessary external JAR-files via a URLClassLoader as follows:
from java.net import URL, URLClassLoader
from java.lang import ClassLoader
from java.io import File
jarFilePath = "/path_to/xxx.jar"
if jarFilePath not in sys.path:
sys.path.append(jarFilePath)
# add the jar to the ClassLoader
m = URLClassLoader.getDeclaredMethod("addURL", [URL])
m.accessible = 1
m.invoke(ClassLoader.getSystemClassLoader(),
[File(jarFilePath).toURL()])
import <<some class from xxx.jar>>
This no longer works, because the underlying JRE implementation has changed for Java 11 (the system class loader is no URL class loader any longer). The error message is
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: object is not an instance of declaring class in <script> at line number 13
Traceback (most recent call last):
File "<script>", line 13, in <module>
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: object is not an instance of declaring class
Is there any trick to get this problem solved in the Jython engine of Modelio?
Best regards, Prof. Spock