Just curious - Are you trying this out of your own interest? And are you planning to use this in production. I would strongly recommend not to do this in production. As for using something like this in development, there's JavaRebel which uses a javaagent to achieve this stuff.
Around a couple of months back, we had a product promo for JavaRebel in our IDE forum. You can look search that forum for related topics. For example this one.