I have wrote some code to compile a Java source code. It then produces the .class file. The problem is how do I run it?
For example, I am ok with the name of the pro
You need to create a classloader (a URLClassLoader
will probably be fine) which will load the just-compiled class file. (So for a URLClassLoader
, the compilation output path should be one of the URLs).
Then, load the compiled class using the classloader, and execute it using reflection.
Class c = cl.loadClass("ClassName");
... etc.