I need to take input at runtime and create a new class with it, and load it into the JVM to run.
Although this can quickly become an abstract question with minimal concrete answers, and therefore be marked "Not appropriate for stackoverflow", I really am looking for some concrete answers on this.
I have read a ton of resources regarding this. Answers I've uncovered range from manipulating the byte code (not even sure how I would begin that), to recursively loading all classes in the JVM which doesn't actually seem possible because this seems like it would cause an infinite loop type scenario.
Currently I'm writing a .java
file dynamically and then getting a refference to the System compiler and using that to compile to a class file. Then I use the defineClass()
method on the ClassLoader
class to attempt to load it into the JVM.
After performing these steps I'm getting a NoClassDefError
thrown which makes sense, I just need some input on how to correctly get this new, dynamically written class loaded into the JVM?
In response to a concern brought forth by someones comment, this is 100% experimentation and for learning purposes only. This is not something that would go into production.