Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idiomatic JAR file load for Jython does no longer work in 5.3 #86

Open
prof-spock opened this issue Nov 16, 2023 · 0 comments
Open

Idiomatic JAR file load for Jython does no longer work in 5.3 #86

prof-spock opened this issue Nov 16, 2023 · 0 comments

Comments

@prof-spock
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant