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

Add examples for loading a jar after the JVM is started #504

Open
Thrameos opened this issue Jul 1, 2019 · 4 comments
Open

Add examples for loading a jar after the JVM is started #504

Thrameos opened this issue Jul 1, 2019 · 4 comments
Labels
documentation Issue with our documentation (misleading, missing, bad) enhancement Improvement in capability planned for future release

Comments

@Thrameos
Copy link
Contributor

Thrameos commented Jul 1, 2019

A common issue that I see in forums is trying to add something to the classpath after the JVM has already be started. As we can't restart the JVM that is already in progress, it can be an issue if multiple modules are using JPype. Once a module has started the JVM, then nothing can add to the classpath leading to a fail. I am not sure if there is a good procedure for this case in terms of getting the existing ClassLoader to change paths, but there is no reason that we can't create a second classloader for a runtime supplied path and use it for loading.

We should work through an example of this common problem and see how arduous it is. If the pattern is very difficult then we should see if some additional support of needed in the library to simplify it.

Not sure whether this is a long term or short term project. If user respond to request this feature, I can move it up on the schedule. Otherwise it will happen as part of the next documentation pass.

@Thrameos Thrameos added enhancement Improvement in capability planned for future release documentation Issue with our documentation (misleading, missing, bad) labels Jul 1, 2019
@pelson
Copy link
Contributor

pelson commented Mar 27, 2020

I think this would be a very worthwhile thing to document (and potentially provide an API/helper for). Interestingly there is a nice answer at https://stackoverflow.com/a/34111824/741316 which ironically uses JPype and IPython to interact with the classpath.

@Thrameos
Copy link
Contributor Author

I have largely forgotten about this one. I have worked a bit with class loaders since this original perhaps I should cycle back to this.

@pelson
Copy link
Contributor

pelson commented May 19, 2022

There was an addition of addClassPath in v1.2.0 which helps with this. It isn't really documented properly though (it is only mentioned in a table in https://jpype.readthedocs.io/en/latest/quickguide.html#starting-jpype)

@Thrameos
Copy link
Contributor Author

Yes addClassPath allows adding of classes after the jvm is started. But to has weird restrictions. Certain classes such as sql drivers can only be loaded by the application loader. Basically the security model only recognizes classes loaded by the same classs loader. I wanted to make it so all classes used the dynamic class loader, but then sql does not work. So we end up with two tiers of classes, the priviliged loaded with jvm and the second tier loaded after. Mixing the two gave odd results hence the difficulty I had with documenting it. For non sql it is best if all went with the dynamic so less mixing. But hard to achive that without starting jvm then calling addclasspath to deliberately force them as dynamic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issue with our documentation (misleading, missing, bad) enhancement Improvement in capability planned for future release
Projects
None yet
Development

No branches or pull requests

2 participants