The goal is to implement a web application that can execute methods of .class files that has been uploaded. The uploaded class file is available as a byte[]. The public class in this .class file implements a specific interface.
After the upload, I’d like to call a method (interface implementation).
Is there a way to do so in a running java application? If yes, how?
Btw. I’m aware of the security risks.
Shouldn’t be too hard:
ClassLoader#defineClass(String, byte[], int, int).YourInterface.class.isAssignableFrom(loadedClass);).Class<?>you just got on step 1. (e.g.YourInterface obj = (YourInterface)loadedClass.newInstance();).obj.shinyMethod();Re creating your own classloader: Here’s a simple one that just delegates to the system class loader: