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

Use custom class loader for autoclass #316

Open
hanslovsky opened this issue Dec 11, 2017 · 3 comments
Open

Use custom class loader for autoclass #316

hanslovsky opened this issue Dec 11, 2017 · 3 comments

Comments

@hanslovsky
Copy link

hanslovsky commented Dec 11, 2017

We are currently trying to use groovy grape to load classes from jars that were not on the initial class path to allow for a more interactive scripting experience. We can resolve and download the required jars but we cannot load the classes through autoclass. It seems the issue is with FindClass:

Since Java 2 SDK release 1.2, when FindClass is called through the Invocation Interface, there is no current native method or its associated class loader. In that case, the result of ClassLoader.getSystemClassLoader is used. This is the class loader the virtual machine creates for applications, and is able to locate classes listed in the java.class.path property.

We tried replicating autoclass to accept a class object that was created like this:

loaded_class = java.lang.ClassLoader.loadClass(clazz)
autoclass(loaded_class)
print(loaded_class)
<Class at 0x7f9ab7a70468 jclass=java/lang/Class jself=<LocalRef obj=0x106e178 at 0x7f9ab7a863f0>>

I do not know how to replicate
reflect.py:159:
More specifically, I cannot replicate jnius_export_func.pxi:30-33

cls = Class(noinstance=True)
cls.instanciate_from(create_local_ref(j_env, jc))
j_env[0].DeleteLocalRef(j_env, jc)
return cls

for loaded_class as created through a custom class loader as above.

If you have some hints or pointers for me, what I need to modify, I am willing to make the changes and create the PR.

Related to this, is there a way to access the jenv or is the method get_jnienv exposed?

@hanslovsky
Copy link
Author

If you have any hints on this, we would gladly do our part and add custom class loader functionality in a pull request. At the moment, we are kind of at a dead end here, though.

@bnuzhouwei
Copy link

Is there any progress in the past few years, the feature is alow import for many cases to extension a powfully pluigein system.

@cmacdonald
Copy link
Contributor

cant you use you access your own classloader from Python, and then use its loadClass(str) method?

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

No branches or pull requests

4 participants