What you want is something like Janino . We have used it for many years. You give it (near the standard) code, and it gives you classes so you can use them. In fact, it has quite a few different modes and supports 1.5 syntactic sugar and auto-boxing, etc.
If you call javac, you will not only be ready for anything you need, you will have to process the class in the right place or do an additional class loader.
Yanino is very easy. This should be exactly what you are looking for.
MBCook
source share