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

Support for reloading class files when changed (hot swapping) #48

Closed
tomtom opened this issue Jun 12, 2015 · 4 comments
Closed

Support for reloading class files when changed (hot swapping) #48

tomtom opened this issue Jun 12, 2015 · 4 comments

Comments

@tomtom
Copy link

tomtom commented Jun 12, 2015

During development classes tend to change quite often. Currently rJava seems to load a class definition only once. I have to restart R in order to test a new version of a Java class.

Is there a way to make rJava "reload" a class definition somehow? I experimented with a custom class loader but with no avail.

@s-u
Copy link
Owner

s-u commented Jun 12, 2015

That is unfortunately not allowed by Java - mainly because you'd have multiple versions of the same class floating around causing chaos since there is no way to force all objects of a given class to de-allocate (due to dependencies etc.). There is a hack if you split your classes into interfaces since it's ok to load additional implementations of the same interface which is pretty much the only way you can do this in Java, but that means you have to re-factor your code accordingly.

See also
http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html#dynamicreloading

@s-u s-u closed this as completed Jun 12, 2015
@tomtom
Copy link
Author

tomtom commented Dec 13, 2016

Is there a way to tear down the whole jvm and start anew?

@s-u
Copy link
Owner

s-u commented Dec 13, 2016

No, there is no de-initialization, because there is no way to clear out all possible references of R objects - see #25

@s-u
Copy link
Owner

s-u commented Jan 23, 2022

FWIW rJava 1.0 supports hierarchy of class loaders, so it is now possible to create a new loader for each version of the class. This is natively supported by .jpackage(..., own.loader=TRUE), but can be also used independently (by creating a new child loader). API functions now take a class.loader argument so new instances can use the new version of the class.

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

2 participants