Is there a way to emit Java bytecode in memory and execute it?
I know that there's JavaCompiler class, but I'm asking something like Reflection.Emit of .NET platform.
-
1the JavaCompiler class can be used to work entirely in memory (i wrote a libray to do this some years ago) not that it makes much difference. ;-)Peter Lawrey– Peter Lawrey2012-12-25 13:21:39 +00:00Commented Dec 25, 2012 at 13:21
-
+1 @PeterLawrey, is this library open source?gsscoder– gsscoder2012-12-25 19:09:43 +00:00Commented Dec 25, 2012 at 19:09
Add a comment
|
3 Answers
You need to play with the class loader to load dynamically some class. There are some interesting SO questions on the subject:
Comments
This is possible but this requires the end user also to install JDK. Compile the bytecode to memory and create a new java process and start it. You can also execute java source directly.
See Beanshell2.